// Your Name : msglm // Date: Feb-17-2022 // Program Title: MENU TEMPLATE with IF ELSE // Program Description: a program with a menu structure that will allow the user to choose an option to calculate area for a: Rectangle, Circle, and a Triangle #include #include #include #include using namespace std; // Named constants int main() { // Variable declaration int choice; double area; char option; //Program title and description for the user cout << "MENU TEMPLATE with IF ELSE" << endl << endl; // User input do { do { cout << "Choose the corresponding number for what task you want to complete." << endl; cout << "1 - Perform task #1 : Rectangle area" << endl; cout << "2 - Perform task #2 : Circle area" << endl; cout << "3 - Perform task #3 : Triangle area" << endl; cout << "Enter selected number here: "; cin >> choice; if (!cin || choice<1 || choice>4) { cout << "Invalid input selection\n\n"; //This will purge the garbage data cin.clear(); //Clears error flag cin.ignore(100, '\n'); //Purges 100 characters of input } } while (!cin || choice<1 || choice>4); // Calculations // Output to the screen //This if-else statement need not exist: a switch statement would be much more optimal if (choice == 1) { double height; double width; //User Input cout << "Perform task #1 : Rectangle area" << endl; cout << "Input the height in cm: \n"; cin >> height; cout << "Input the width in cm: \n"; cin >> width; //Calculation area = height * width; //Output cout << "Area of the rectangle is " << area << " cm^2 \n"; } else if (choice == 2) { cout << "Perform task #2 : Circle area" << endl; double inputRadius; string measurement; const double pi = 3.14159; //User Input cout << "Please Input the Desired Radius for your Circle in cm: "; cin >> inputRadius; //Output cout << "Area of the circle is " << pi*pow(inputRadius, 2) << "cm^2 \n"; } else if (choice == 3) { double height; double base; //User Input cout << "Perform task #3 : Triangle area" << endl; cout << "Input the height in cm: \n"; cin >> height; cout << "Input the base in cm: \n"; cin >> base; //Output cout << "Area of the rectangle is " << (height*base)/2 << " cm^2 \n"; } else cout << "Terminating" << endl; cout << "Would you like to run again? (Y/N): "; cin >> option; cout << "\033c"; } while (option == 'Y' || option == 'y'); return 0; } /*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with this program. If not, see . */