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, "XOR");
21 displayMenuEntry(5, "Exit");
24 /** Prompt the user for his operation choice.
26 * @return The selected operation. No invalid value can be returned.
28 int promptOperation() {
33 result
= promptValue("Choose an option");
35 if (result
>= 1 && result
<= 5) {
39 puts("Please choose a valid option (1-5)");
46 int operation
= promptOperation();
52 int initialValue
= promptValue("Initial value");
55 int nextValue
= promptValue("Next value");
64 initialValue
+= nextValue
;
69 initialValue
-= nextValue
;
74 initialValue
*= nextValue
;
79 initialValue
^= nextValue
;
83 printf("Result: %d\n", initialValue
);