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

Menu Driven Program Using Loops

The document presents a C++ program that implements a menu-driven calculator using loops. Users can choose between addition, subtraction, multiplication, and division, with error handling for division by zero. The program continues to prompt for user input until the exit option is selected.

Uploaded by

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

Menu Driven Program Using Loops

The document presents a C++ program that implements a menu-driven calculator using loops. Users can choose between addition, subtraction, multiplication, and division, with error handling for division by zero. The program continues to prompt for user input until the exit option is selected.

Uploaded by

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

Menu Driven Program Using Loops

#include <iostream>
using namespace std;

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

do {
cout << "\n===== MENU =====" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;

switch(choice) {
case 1:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "Result = " << num1 + num2 << endl;
break;

case 2:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "Result = " << num1 - num2 << endl;
break;

case 3:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "Result = " << num1 * num2 << endl;
break;

case 4:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
if(num2 != 0)
cout << "Result = " << num1 / num2 << endl;
else
cout << "Error! Division by zero is not allowed." << endl;
break;

case 5:
cout << "Exiting program..." << endl;
break;

default:
cout << "Invalid choice! Please try again." << endl;
}

} while(choice != 5);

return 0;
}

You might also like