1
|
1 // A simple calculator
|
0
|
2
|
|
3 #include <stdio.h>
|
|
4 #include <stdlib.h>
|
|
5 #include <unistd.h>
|
|
6 #include <math.h>
|
|
7
|
|
8 int main(int argc, char* argv[]){
|
|
9
|
|
10 if (argc == 1) { puts("Quickcalculator 1Add 2Sub 3Mul 4Div"); exit(1);}
|
|
11 // Get numbers
|
1
|
12 int value1 = atoi(argv[1]);
|
|
13 int value2 = atoi(argv[3]);
|
0
|
14
|
|
15 // Determine operation
|
|
16 unsigned int operation = atoi(argv[2]); // addition subtraction multiplication division
|
|
17 // Do calculation and print
|
|
18 int finalvalue;
|
|
19
|
|
20 if (operation == 1){finalvalue = value1 + value2;}
|
|
21 if (operation == 2){finalvalue = value1 - value2;}
|
|
22 if (operation == 3){finalvalue = value1 * value2;}
|
|
23 if (operation == 4){finalvalue = value1 / value2;}
|
|
24
|
|
25 printf("%d\n", finalvalue);
|
|
26 exit(0);
|
|
27 }
|