Part 4 does not say what its suppose to say but then again I have been one it for hours.
I am new to C++ so if my code is perfect do not tear me apart about it. And no mean comments just please help.
I'm using a while loop.
Loops are difficult for me. I get everything else in c++.
I understand loops so much better after doing thisi then when I started.
#include <iostream> #include <iomanip> using namespace std; int main() { // contains the variables // variables double AREA; double circle; double Triangle; int Quit; int choice; double pi; //radius pi = 3.14159; double radius; /// rectangle double Rectangle; double area; double number; double length; double width; //triangle double TRIANGLE; double AREA3; double base; double height2; double area2; // quit double WAY2; double answer; char input; char n; //asks the user which one and displays it //constants for menu choices const int CIRCLE_AREA1 = 1, Rectangle_AREA2 = 2, TRIANGLE_AREA3 = 3, QUIT_WAY2 = 4; // display the choices cout << "1. Calculate the Area of a Circle\n\n" << "2. Calculate the area of a Rectangle \n\n" << "3. Calculate the Area of a Triangle \n\n" << "4. Quit \n\n"; cin >> choice; if (choice >=1 && choice <=4){ //if choice between 1-4 cout << "Thanks for you choice" <<endl; } while(choice >=1 && choice <=4){ switch (choice) //circle area { case CIRCLE_AREA1: cout << "enter any number" <<endl; cin >> radius; if (radius < 0 ) { cout << "You must enter a positive number" <<endl; } else { AREA = radius * radius * pi; cout << "The radius of the circle is " << AREA <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } //rectangle area while(choice >=1 && choice <=4){ switch (choice) { case Rectangle_AREA2: cout << " Put a length of a rectangle " <<endl; cin >> length; if ( length < 0 ) { cout <<"You must enter a postive number " <<endl; } else { cout << "Enter a width of a rectangle" <<endl; cin >> width; area = length * width; cout << "The area of the rectangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } // while(choice >=1 && choice <=4){ switch (choice) { case TRIANGLE_AREA3: cout << " enter any number " <<endl; cin >> base; if ( base < 0 ) { cout <<"You must enter a postive number " <<endl; } else { cout << "Enter a height of a triangle base" <<endl; cin >> height2; area2 = base * height2 * 0.5; cout << "The area of the triangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } //quit choice while(choice >=1 && choice <=4){ switch (choice) { case QUIT_WAY2: cout << "Enter a length OF THE triangle base" <<endl; cin >> base; cin >> choice; break; } } return 0; } } }