annotate quickcalc.c @ 0:9bf878c59a1d

Finished
author VilyaemKenyaz
date Fri, 25 Aug 2023 13:42:00 -0400
parents
children dfce17cc481b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
1 // A simple calculator, if no arguments do wizard mode.
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
2
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
3 #include <stdio.h>
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
4 #include <stdlib.h>
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
5 #include <unistd.h>
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
6 #include <math.h>
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
7
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
8 int main(int argc, char* argv[]){
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
9
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
10 if (argc == 1) { puts("Quickcalculator 1Add 2Sub 3Mul 4Div"); exit(1);}
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
11 // Get numbers
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
12 unsigned int value1 = atoi(argv[1]);
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
13 unsigned int value2 = atoi(argv[3]);
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
14
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
15 // Determine operation
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
16 unsigned int operation = atoi(argv[2]); // addition subtraction multiplication division
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
17 // Do calculation and print
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
18 int finalvalue;
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
19
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
20 if (operation == 1){finalvalue = value1 + value2;}
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
21 if (operation == 2){finalvalue = value1 - value2;}
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
22 if (operation == 3){finalvalue = value1 * value2;}
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
23 if (operation == 4){finalvalue = value1 / value2;}
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
24
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
25 printf("%d\n", finalvalue);
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
26 exit(0);
9bf878c59a1d Finished
VilyaemKenyaz
parents:
diff changeset
27 }