0% found this document useful (0 votes)
12 views2 pages

Out Put Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Out Put Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

void showMenu() {
printf("Simple Calculator\n");
printf("=================\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Exit\n");
printf("Choose an operation: ");
}

int main() {
int choice;
double num1, num2, result;

while (1) {
showMenu();
scanf("%d", &choice);

if (choice == 5) {
printf("Exiting...\n");
break;
}

printf("Enter first number: ");


scanf("%lf", &num1);
printf("Enter second number: ");
scanf("%lf", &num2);

switch (choice) {
case 1:
result = num1 + num2;
printf("Result: %lf\n", result);
break;
case 2:
result = num1 - num2;
printf("Result: %lf\n", result);
break;
case 3:
result = num1 * num2;
printf("Result: %lf\n", result);
break;
case 4:
if (num2 != 0) {
result = num1 / num2;
printf("Result: %lf\n", result);
} else {
printf("Error: Division by zero is not allowed.\n");
}
break;
default:
printf("Invalid choice. Please try again.\n");
break;
}
printf("\n");
}
return 0;
}

You might also like