1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
double radius, pi, length, width, base, height, area; //<--added area
pi = 3.14159;
do
{
cout << "What would you like to do?" << endl;
cout << "1. Calculate the Area of a Circle" << endl;
cout << "2. Calculate the Area of a Rectangle" << endl;
cout << "3. Calculate the Area of a Triangle" << endl;
cout << "4. Quit" << endl; //<-- added 4 so user knows what to hit to quit
cout << "Enter 1, 2, 3, or 4: " << endl; //<-- added a: "
cin >> choice; //<-- cin use: >>
while (choice < 1 || choice > 4)
{
cout << "Please enter a valid choice" << endl;
cout << "Enter 1, 2, 3, or 4: " << endl;
cin >> choice;
}
switch (choice)
{
case 1:
cout << "What is the radius of the circle?" << endl;
cin >> radius;
area = pi*pow(radius, 2.00); //<-- added a: ; and area needed to be decalared a variable
cout << "The area of the circle is " << area << endl;
break;
case 2:
cout << "What is the length of the rectangle? " << endl;
cin >> length;
cout << "What is the width of the rectangle? " << endl;
cin >> width;
area = length*width;
cout << "The area of the rectangle is " << area << endl;
break;
case 3:
cout << "What is the length of the triangle's b-ase? " << endl;
cin >> base; //<-- cin use: >>
cout << "What is the height of the triangle? " << endl;
cin >> height; //<-- cin use: >>
area = .5*(base*height);
cout << "The area of the triangle is " << area << endl;
break;
case 4: cout << "Goodbye" << endl;
}
} while (choice <= 3 && choice >= 1);
return 0;
}
|