Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Basic calculator MISSING MAIN MENU LOOP
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int main()
- {
- int choice;
- //Main Menu
- cout << "Enter the number next to the calculation you would like to use, or \n if you would like to exit." << endl;
- cout << endl;
- cout << endl;
- cout << "1. Addition" << endl;
- cout << "2. Subtraction" << endl;
- cout << "3. Multiplication" << endl;
- cout << "4. Division" << endl;
- cout << "5. Exit" << endl;
- cout << endl;
- cout << endl;
- cin >> choice;
- //Addition statement
- if (choice == 1)
- {
- double firstNumber;
- double secondNumber;
- double result;
- cout << "You chose addition." << endl;
- cout << endl;
- cout << "Enter the first number: ";
- cin >> firstNumber;
- cout << endl;
- cout << "Now, enter the second number to add: ";
- cin >> secondNumber;
- cout << endl;
- result = firstNumber + secondNumber;
- cout << firstNumber << " + " << secondNumber << " = " << result << endl;
- cout << endl;
- cout << endl;
- cout << "Press any key to exit.";
- getch();
- return 0;
- }
- //Subtraction statement
- else if (choice == 2)
- {
- double firstNumber;
- double secondNumber;
- double result;
- cout << "You chose subtraction." << endl;
- cout << endl;
- cout << "Enter the first number: ";
- cin >> firstNumber;
- cout << endl;
- cout << "Enter the second number to subtract: ";
- cin >> secondNumber;
- cout << endl;
- result = firstNumber - secondNumber;
- cout << firstNumber << " - " << secondNumber << " = " << result << endl;
- cout << endl;
- cout << endl;
- cout << "Press any key to exit.";
- getch();
- return 0;
- }
- //Multiplication statement
- else if (choice == 3)
- {
- double firstNumber;
- double secondNumber;
- double result;
- cout << "You chose multiplication." << endl;
- cout << endl;
- cout << "Enter the first number: ";
- cin >> firstNumber;
- cout << endl;
- cout << "Enter the second number to multiply: ";
- cin >> secondNumber;
- cout << endl;
- result = firstNumber * secondNumber;
- cout << firstNumber << " * " << secondNumber << " = " << result << endl;
- cout << endl;
- cout << endl;
- cout << "Press any key to exit.";
- getch();
- return 0;
- }
- //Division statement
- else if (choice == 4)
- {
- double firstNumber;
- double secondNumber;
- double result;
- cout << "You chose division." << endl;
- cout << endl;
- cout << "Enter the first number: ";
- cin >> firstNumber;
- cout << endl;
- cout << "Enter the second number to divide: ";
- cin >> secondNumber;
- cout << endl;
- result = firstNumber / secondNumber;
- cout << firstNumber << " / " << secondNumber << " = " << result << endl;
- cout << endl;
- cout << endl;
- cout << "Press any key to exit.";
- getch();
- return 0;
- }
- //Exit statement
- else if (choice == 5)
- {
- return 0;
- }
- //Loop after invalid choice
- do
- {
- cout << "You entered an invalid choice." << endl;
- cout << "Please choose one of the following:" << endl;
- cout << endl;
- cout << endl;
- cout << "1. Addition" << endl;
- cout << "2. Subtraction" << endl;
- cout << "3. Multiplication" << endl;
- cout << "4. Division" << endl;
- cout << "5. Exit" << endl;
- cout << endl;
- cin >> choice;
- }
- while (choice < 1 || choice > 5);
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "Press any key to exit.";
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment