-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathcalculator.c
executable file
·52 lines (45 loc) · 1.09 KB
/
calculator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Author:
* Date:
*
* This programs provides basic calculator functionality
* allowing a user to enter two operands and to compute
* various calculated values.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv) {
double a, b, result;
int choice;
printf("Enter operand a: ");
scanf("%lf", &a);
printf("Enter operand b: ");
scanf("%lf", &b);
printf("Enter operation:\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Minimum\n");
printf("(6) log_a(b)\n");
scanf("%d", &choice);
if(choice == 1) {
printf("%f", a + b);
} else if(choice == 2) {
result = a - b;
printf("%f", result);
} else if(choice == 3) {
//TODO: handle this case (multiplication)
} else if(choice == 4) {
//TODO: handle this case (division)
} else if(choice == 5) {
//TODO: handle this case (minimum)
} else if(choice == 6) {
//TODO: handle this case (log_a(b))
} else {
printf("Please input a valid operator next time");
}
return 0;
}