4 /** Display a prompt to the user then wait for an integer input. */
5 int promptValue(const char* prompt
) {
6 printf("%s:\n", prompt
);
12 void displayMenuEntry(int index
, const char* label
) {
13 printf("%d | %s\n", index
, label
);
17 displayMenuEntry(1, "Addition");
18 displayMenuEntry(2, "Substraction");
19 displayMenuEntry(3, "Multiplication");
20 displayMenuEntry(4, "Exit");
23 /** Prompt the user for his operation choice.
25 * @return The selected operation. No invalid value can be returned.
27 int promptOperation() {
32 result
= promptValue("Choose an option");
34 if (result
>= 1 && result
<= 4) {
38 puts("Please choose a valid option (1-4)");
45 int operation
= promptOperation();
51 int initialValue
= promptValue("Initial value");
54 int nextValue
= promptValue("Next value");
63 initialValue
+= nextValue
;
68 initialValue
-= nextValue
;
73 initialValue
*= nextValue
;
77 printf("Result: %d\n", initialValue
);