C++ program to select a shape (rectangle, square, or circle), input dimensions, and calculate the area: #include #include using namespace std; const double Pi = 3.14; int main() { char shape = ' '; double l = 0.0; double w = 0.0; double A = 0.0; double r = 0.0; while (shape != '0') { cout << "This program will find the area of a shape." << endl << endl; cout << "Shape Menu: \n (r) rectangle \n (s) square \n (c) circle \n (0) exit" << endl; cout << "Type the letter corresponding to your desired option: "; cin >> shape; cout << endl; switch(shape) { case 'r': case 'R': cout << "You selected a rectangle." << endl << endl; cout << "Enter the length of the rectangle: "; cin >> l; cout << "Enter the width: "; cin >> w; if (cin.fail()) { cout << "Invalid input data. Expected a floating point value, but a character was entered." << endl; cout << "Program terminating; please re-execute the program if you wish to begin again." << endl; return 1; } A = l*w; //Formula to calculate area of rectangle cout << "The area is " << A << " units squared." << endl; cout << endl; break; case 's': case 'S': cout << "You selected a square." << endl << endl; cout << "Enter the length of the square's side: "; cin >> l; if (cin.fail()) { cout << "Invalid input data. Expected a floating point value, but a character was entered." << endl; cout << "Program terminating; please re-execute the program if you wish to begin again." << endl; return 1; } A = l*l; //Formula to calculate area of square cout << "The area is " << A << " units squared." << endl; cout << endl; break; case 'c': case 'C': cout << "You selected a circle." << endl << endl; cout << "Enter the length of the circle's radius: "; cin >> r; if (cin.fail()) { cout << "Invalid input data. Expected a floating point value, but a character was entered." << endl; cout << "Program terminating; please re-execute the program if you wish to begin again." << endl; return 1; } A = Pi*r*r; //Formula to calculate area of circle cout << "The area is " << A << " units squared." << endl; cout << endl; break; case '0': cout << "Terminating program. Have a nice day!" << endl; return 1; default: cout << "Invalid menu input. Type t to try again or 0 to exit." << endl; cin >> shape; cout << endl; } } return 0; }