forked from CPRO-Session1/Assignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.c
More file actions
54 lines (42 loc) · 1.24 KB
/
Copy pathcalculator.c
File metadata and controls
54 lines (42 loc) · 1.24 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
://Clarke Littlejohn
//A simple five function calculator
#include <stdio.h>
int main(){
int value1;
int value2;
int value3;
float value4;
char oper;
printf("\nEnter one of the five characters below to peform that operation.");
printf("\n+: value1 plus value2 -: value1 minus value2 *: value1 times value2\n");
printf("/: value1 divided value2 %%: the remainder of value1 divided by value2\n");
scanf("%c",&oper);
printf("Enter a number for the first value:");
scanf("%d",&value1);
printf("\nEnter a number for the second:");
scanf("%d",&value2);
switch(oper){
case '%':
value3=value1%value2;
printf("%d%%%d=%d\n",value1,value2,value3);
break;
case '+':
value3=value1+value2;
printf("%d+%d=%d\n",value1,value2,value3);
break;
case '-':
value3=value1-value2;
printf("%d-%d=%d\n",value1,value2,value3);
break;
case '*':
value3=value1*value2;
printf("%d*%d=%d\n",value1,value2,value3);
break;
case '/':
value4=(float) value1/(float) value2;
printf("%d/%d=%.2f\n",value1,value2,value4);
break;
default:
printf("You did not enter one of the five symbols, please restart the program.\n");
}
}