while loop won't repeat

my program is about a menu of different shapes will be shown to a user at the beginning of the program (and again after each calculation).
The user will select an option and the program will then prompt for additional information that is specific to the shape,
perform the surface area calculation, and display the results for the shape.This process will continue until the user decides to quit.

here's my program


#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;
# define PI 3.14159
int main ()    
    {
    int choice;
    
     
    cout << "Surface Area Calculator" <<endl;
	cout << "1) Sphere" <<endl;
	cout << "2) Cone" <<endl;
	cout << "3) Rectangular Prism" <<endl;
	cout << "4) Pyramid" <<endl;
	cout << endl;
	cout << "5) Quit" <<endl;
	cout << endl;
	cout << "Enter your choice" <<endl;
	cin >> choice;
    
    float length, width, radius, height;
    float areasphere, areacone, areaprism, areapyramid;
    
    
    while (choice > 5 || choice <= 0 )
    {
	cout << choice << "  is an invalid choice. Try again:" <<endl;
	cin >> choice;
    }
    
	if (choice == 1)
	{
	cout << "enter the radius for the sphere:"<<endl;
	cin >> radius;
	areasphere = 4 * PI * radius * radius;
	cout << endl;
	cout << "The surface area of a sphere with radius " << radius << " is " << areasphere << fixed<<setprecision(4)<<endl;
    }
   	else if (choice == 2)
    {     
    cout << "Enter the radius of the base of the cone:"<< endl;
	cin >> radius;
	cout << endl;
	cout << "Enter the length of the side of the cone:" <<endl;
	cin >> length;
	cout << endl;
	areacone = (PI * radius * length) + (PI * radius * radius);
	cout << "The surface area of a cone with radius " << radius <<" the side length " <<length <<" is " <<areacone << fixed<<setprecision(4) <<endl;
	}
    else if ( choice == 3)
    {
    cout << "Enter the length of the side of the prism:" <<endl;
	cin >> length;
	cout << endl;
	cout << "Enter the width of the side of the prism:" <<endl;
	cin >> width;
	cout << endl;
	cout << "Enter the height of the side of the prism:" <<endl;
	cin >> height;
	cout << endl;
	areaprism = ( 2 * length * width ) + ( 2 * width * height ) + ( 2 * length * height );
	cout << "The surface area of the prism with length, " <<length <<" width, " <<width <<" and height " <<height <<" is " << areaprism <<fixed<<setprecision(4) <<endl;
    }
    
    else if ( choice == 4)
    {
	cout << "Enter the length of the base of the pyramid:"<<endl;
	cin >> length;
	cout << endl;
	cout << "Enter the slant height of the pyramid:"<<endl;
	cin >> height;
	cout << endl;
	areapyramid = ( 2 * length * height ) + (length * length);
	cout << "The surface area of the pyramid with base " <<length <<" and slant height " <<height <<" is " <<areapyramid <<fixed<<setprecision(4)<<endl;   
    }
    else if (choice == 5)
    {
    }
    system ("pause");
    return 0;
    }
I know i need another while loop to repeat itself while (choice == 5) i can't seem to firgure it out where to put it any suggestion?
Last edited on
Code tags, not output, and stop bolding everything because it's stupid and childish.
Your condition in the only while loop, which I presume you are talking about, is wrong. You want to make them repeat if they enter something besides 0-5, right? That condition will be true only IF they enter zero to five.
I want it to repeat untill they enter 5, beucase 1-4 are calulation for surface area of spere, cone, prism, and pyramid and also display an error message if their menu choice is greater than 5 or less than equal to zero.
Topic archived. No new replies allowed.