comparison quickcalc.c @ 0:9bf878c59a1d

Finished
author VilyaemKenyaz
date Fri, 25 Aug 2023 13:42:00 -0400
parents
children dfce17cc481b
comparison
equal deleted inserted replaced
-1:000000000000 0:9bf878c59a1d
1 // A simple calculator, if no arguments do wizard mode.
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
12 unsigned int value1 = atoi(argv[1]);
13 unsigned int value2 = atoi(argv[3]);
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 }