repl.it
@ArjunArunkumar/

calculator

C

Simple calculator

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>

int main(void) {
	float numberOne;
	float numberTwo;
	int operation;
	float answer;

	printf("Simple calculator\n");
	printf("Enter first number\n");
	scanf("%f", &numberOne);
	printf("Enter operation ¦1 is +¦ 2 is -¦ 3 is multiply¦ 4 is divide¦\n");
	scanf("%d",&operation);
	printf("Enter second number\n");
	scanf("%f", &numberTwo);

	switch(operation){
		case 1:
		answer = numberOne + numberTwo;
		printf("%f", answer);
		break;
		case 2:
		answer = numberOne - numberTwo;
		printf("%f", answer);
		break;	
		case 3:
		answer = numberOne * numberTwo;
		printf("%f", answer);
		break;
		case 4:
		answer = numberOne / numberTwo;
		printf("%f", answer);
		break;	
		
	}



}