PAV CALCULATOR (P=PERIMETER, A= AREA, V= VOLUME)

Good day
I have a challenge in making my program to repeat its process

#include <iostream>
#include <cmath>
using namespace std;

int main()
{ float PI=3.1415926535;
int x;

cout <<"*******PAV CALCULATOR*******"<<endl;


cout <<"\nSELECT SCOPE OF FOCUS"<<endl;


cout <<"1.Volume\n2.Area\n3.Perimeter"<<endl;
cin >>x;

/** char again = 'y';
while ( again == 'y')**/
switch(x)
{
case 1:
int c;

cout << "CALCULATE VOLUME OF THE FOLLOWING SHAPES" << endl;
cout <<"\nVolume"<<endl;
cout <<"select a shape"<<endl;
cout <<"\n1.Sphere\n 2.Cone\n 3.Pyramid"<<endl;
cin >>c;


switch (c)
{
case 1:
float r,b;

cout << "CALCULATE VOLUME OF THE SPHERE" << endl;
cout <<"Sphere"<<endl;
cout <<"Enter radius"<<endl;
cin >>r; // r = radius

b=(((4/3)*(PI))*pow(r,3));
cout <<"The volume is = "<<b<<endl;
break;

case 2:
float a,d,e;

cout << "CALCULATE VOLUME OF A CONE\n" << endl;
cout <<"Cone"<<endl;
cout <<"Enter radius"<<endl;
cin >>a; //r= radius

cout <<"Enter height"<<endl;
cin >>d; //d= height

e=((PI*pow(c,2))*(d/3));
cout <<"The volume is = "<<e<<endl;
break;

case 3:
float f,g,h,i;

cout << "CALCULATE VOLUME OF A PYRAMID" << endl;
cout <<"Pyramid"<<endl;
cout <<"Enter length"<<endl;
cin >>f; // f= length of the pyramid

cout <<"Enter width"<<endl;
cin >>g; //g= width of the pyramid

cout <<"Enter height"<<endl;
cin >>h; //h= height of the pyramid

i=((f*g*h)/3);
cout <<"The volume is = "<<i<<endl;
break;
}

break;

case 2:
int f;
cout << "CALCULATE AREA OF THE FOLLOWING SHAPES" << endl;
cout <<"\nArea"<<endl;
cout <<"SELECT SHAPE\n"<<endl;
cout <<"\n1.Parallelogram\n2.Triangle\n3.Trapezoid\n4.Circle\n5.Ellipse\n6.Sphere\n7.Cylinder"<<endl;
cin >>f;
switch (f)
{
case 1:
int a,b,c;
cout << "CALCULATE AREA OF A PARALLELOGRAM" << endl;

cout <<"Parallelogram"<<endl;
cout <<"Enter the height"<<endl;
cin >>a; // a= the height of a parallelogram

cout <<"Enter the width"<<endl;
cin >>b; // b= width of a parallelogram

c=a*b;
cout <<"The area is = "<<c<<endl;
break;

case 2:
int d,e,f;

cout << "CALCULATE AREA OF A TRIANGLE" << endl;

cout <<"Triangle"<<endl;
cout <<"\nEnter the height"<<endl;
cin >>d; // d= the height of a triangle

cout <<"Enter the width"<<endl;
cin >>e; // e= the width of a triangle

f=0.5*(e*d);
cout <<"The area is = "<<f<<endl;
break;

case 3:
int g,h,i,j;

cout << "CALCULATE AREA OF A TRAPEZOID" << endl;

cout <<"Trapezoid"<<endl;
cout <<"\nEnter first length"<<endl;
cin >>g; //f= the first length of a trapezoid

cout <<"Enter second length"<<endl;
cin >>h; // h= the second length of a trapezoid

cout <<"Enter the height"<<endl;
cin >>i; // i= the height of a trapezoid

j=((h+g)/2)*i;
cout <<"The area is = "<<j<<endl;
break;

case 4:
float k,l;

cout << "CALCULATE AREA OFA CIRCLE" << endl;

cout <<"Circle"<<endl;
cout <<"\nEnter the radius"<<endl;
cin >>k; // k= radius of a circle

l=PI*pow(k,2);
cout <<"The area is = "<<l<<endl;
break;

case 5:
float m,n,o;
cout <<"Ellipse"<<endl;
cout <<"\nEnter the height"<<endl;
cin >>m;

cout <<"Enter the width"<<endl;
cin >>n;

o=PI*m*n;
cout<<"The area is = "<<o<<endl;
break;

case 6:
float p,q;

cout << "CALCULATE SURFACE AREA OF A SPHERE" << endl;
cout <<"Sphere"<<endl;
cout <<"\nEnter the radius"<<endl;
cin >>p; // p= radius of a sphere

q=4*PI*pow(p,2);
cout <<"The surface area is = "<<q<<endl;
break;

case 7:
float r,s,t;

cout << "CALCULATE SURFACE AREA OF A CYLINDER" << endl;

cout <<"Cylinder"<<endl;
cout <<"\nEnter radius"<<endl;
cin >>r; //r= radius of a cylinder

cout <<"Enter height"<<endl;
cin >>s; // s= height of a cylinder

t=(2*PI*r*s)+(2*PI*pow(r,2));
cout <<"the whole surface area is = "<<t<<endl;
break;
}
break;


case 3:
int d;
cout << "CALCULATE PERIMETER OF LISTED SHAPES" << endl;

cout <<"\nPerimeter"<<endl;
cout <<"SELECT SHAPE TO CALCULATE"<<endl;
cout <<"1.Rectangle\n2.Parallelogram\n3.Trapezoid\n4.Circle\n5.Ellipse"<<endl;
cin >>d;
switch (d)
{

case 1:
int length,width,perimeter;
cout << "CALCULATE PERIMETER OF A RECTANGLE" << endl;
cout <<"Rectangle"<<endl;
cout <<"\nEnter Length"<<endl;
cin >>length;

cout <<"Enter width"<<endl;
cin >>width;

perimeter=2*(length+width);
cout <<"The perimeter is = "<<perimeter<<endl;

break;

case 2:
int a,b,c;

cout << "CALCULATE PERIMETER OF A PARALLELOGRAM" << endl;
cout <<"Parallelogram"<<endl;
cout <<"\nEnter Length"<<endl;
cin >>a; // a= the length of a parallelogram

cout <<"Enter width"<<endl;
cin >>b; // b= the width of a parallelogram

c=2*(a+b);
cout <<"The perimeter is = "<<c<<endl;

break;

case 3:
int l1,l2,w1,w2,d;

cout << "CALCULATE PERIMETER OF A TRAPEZOID" << endl;

cout<<"Trapezoid"<<endl;
cout<<"\nEnter Length1"<<endl;
cin>>l1; //l1= the first length of the trapezoid

cout<<"\nEnter Length2"<<endl;
cin>>l2; // l2= the second length of the trapezoid

cout <<"Enter width1"<<endl;
cin >>w1; // w1= the first width of the trapezoid

cout <<"Enter width2"<<endl;
cin >>w2; // w2= second width of the trapezoid

d=(l1 + l2 + w1 + w2);
cout <<"The perimeter is = "<<d<<endl;
break;

case 4:
float radius,e;

cout << "CALCULATE PERIMETER OF A CIRCLE" << endl;

cout <<"Circle"<<endl;
cout <<"\nEnter radius"<<endl;
cin >>radius;

e=2* PI*radius;

cout <<"The perimeter is = "<<e<<endl;
cout <<"Circle"<<endl;
break;

case 5:
{
int h,i,j;

cout << "CALCULATE PERIMETER OF AN ELLIPSE" << endl;

cout <<"Ellipse"<<endl;
cout <<"\nEnter Length"<<endl;
cin >>h; // h= length of an ellipse

cout <<"Enter width"<<endl;
cin >>i; // i= width of an ellipse

j=2*(h+i);
cout<<"The perimeter is = "<<j<<endl;
break;

default: cout <<("\n Invalid choice")<<endl;


}




}
// cin >>again;

}
return 0;
}


1
2
3
4
5
6
7
8
char repeat = 'y';
while (repeat == 'y')
{
  /// PUT ALL THE CODE YOU WANT TO BE REPEATED HERE

  cout << "Repeat (enter y to repeat)?";
  cin >> repeat;
}
Thank you, now my program is good
i need a little help again, i want to insert a termination option in my menu, so that the user can terminate if her/she want
add a case for an exit code, and change the loop logic to end if the user input is that code. Its very like what you have already.
Topic archived. No new replies allowed.