-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
85 lines (59 loc) · 1.33 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include "add.h"
#include "sub.h"
#define ADD 1
#define SUB 2
#define EXIT 3
int printMenu() {
int option = 0;
printf("Select an option:\n");
printf("\t1.Add\n");
printf("\t2.Subtract\n");
printf("\t3.Exit\n");
scanf("%d", &option);
return option;
}
void doAdd() {
int num1, num2, result;
// Let's add two numbers with our code
printf("Insert number 1: ");
scanf("%d", &num1);
printf("Insert number 2: ");
scanf("%d", &num2);
result = ADD_twoOperands(num1, num2);
printf("The result of adding these two integers is %d\n", result);
}
void doSub() {
int num1, num2, result;
// Let's subtract two numbers with our code
printf("Insert number 1: ");
scanf("%d", &num1);
printf("Insert number 2: ");
scanf("%d", &num2);
result = SUB_twoOperands(num1, num2);
printf("The result of subtracting these two integers is %d\n", result);
}
void manageOption(int option) {
if (option != ADD && option != SUB && option != EXIT) {
printf("ERROR! Insert a correct number\n");
} else {
switch (option) {
case ADD:
doAdd();
break;
case SUB:
doSub();
break;
}
}
}
int main() {
int option = 0;
printf("Welcome to the simple program! Let's do some maths\n");
do {
option = printMenu();
manageOption(option);
} while (option != EXIT);
printf("Bye!!\n");
return 0;
}