-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.c
More file actions
58 lines (51 loc) · 1.66 KB
/
Copy pathTask.c
File metadata and controls
58 lines (51 loc) · 1.66 KB
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
#include <stdio.h>
#include <stdlib.h>
int main() {
int choice;
double num1, num2, result;
while (1) {
printf("\n=== BASIC CALCULATOR ===\n");
printf("1. Addition (+)\n");
printf("2. Subtraction (-)\n");
printf("3. Multiplication (*)\n");
printf("4. Division (/)\n");
printf("5. Exit\n");
printf("Enter your choice (1-5): ");
scanf("%d", &choice);
if (choice == 5) {
printf("Exiting the calculator. Goodbye!\n");
break;
}
if (choice < 1 || choice > 5) {
printf("Invalid choice! Please select a valid option.\n");
continue;
}
printf("Enter two numbers: ");
scanf("%lf %lf", &num1, &num2);
switch (choice) {
case 1:
result = num1 + num2;
printf("Result: %.2lf + %.2lf = %.2lf\n", num1, num2, result);
break;
case 2:
result = num1 - num2;
printf("Result: %.2lf - %.2lf = %.2lf\n", num1, num2, result);
break;
case 3:
result = num1 * num2;
printf("Result: %.2lf * %.2lf = %.2lf\n", num1, num2, result);
break;
case 4:
if (num2 == 0) {
printf("Error: Division by zero is not allowed!\n");
} else {
result = num1 / num2;
printf("Result: %.2lf / %.2lf = %.2lf\n", num1, num2, result);
}
break;
default:
printf("An unexpected error occurred.\n");
}
}
return 0;
}