here is my revised code, again still with the same issue with menu, but i fixed some other issues
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
const double PI = 3.14159;
int value,choice, radius, length, width, height;
float surface_area_sphere, surface_area_prism, surface_area_cone, surface_area_pyramid;
int menu()
{
cout<<"\n\nSurface Area Calculator"
<<"\n1) Sphere"
<<"\n2) Cone"
<<"\n3) Rectangular Prism"
<<"\n4) Pyramid"
<<"\n\n5) Quit"
<<"\n\nEnter Your Choice: ";
cin>>choice;
while (choice<1 || choice>5)
{
cout<<"\nInvalid choice, please try again: ";
cin>>choice;
}
return(choice);
}
float calcSphere (int radius)
{
surface_area_sphere=(4*PI*radius*radius);
cout<<"The surface area of the sphere with radius "<< radius<<" is: "<<fixed<<setprecision(4)<<surface_area_sphere;
return (surface_area_sphere);
}
int getvalue (string prompt, int lowerBound, int upperBound)
{
cout<<prompt<<lowerBound<<" - "<<upperBound;
cout<<"\n";
cin>>value;
while (value<lowerBound || value>upperBound)
{
cout<<"\nInvalid number, please try again: ";
cin>>value;
return (value);
}
}
float calcPrism (int length, int width, int height)
{
surface_area_prism = ( 2 * length * width ) + ( 2 * width * height ) +
( 2 * length * height );
cout<<"\nThe surface area of a prism with length "<<length<<" and width "<<width<<" and height "<<height<<" is: "<<fixed<<setprecision(4)<<surface_area_prism;
return(surface_area_prism);
}
float calcCone(int radius, int length)
{
surface_area_cone = ( PI * radius * length ) + ( PI * radius*radius );
cout<<"\nThe surface area of a cone with radius "<<radius<<" and length "<<length<<" is: "<<fixed<<setprecision(4)<<surface_area_cone;
return (surface_area_cone);
}
float calcPyramid (int length, int height)
{
surface_area_pyramid = (2*length*height) + (length*length);
cout<<"\nThe surface area of a pyramid with length "<<length<<" and height "<<height<<" is: "<<fixed<<setprecision(4)<<surface_area_pyramid;
return (surface_area_pyramid);
}
int main()
{
while (choice !=5)
{
choice=menu();
if (choice=1)
{
radius=getvalue("\nEnter the radius of the sphere: ", 1, 10);
calcSphere (radius) ;
}
choice=menu();
if (choice=2)
{
length=getvalue("\nEnter the length of the prism: ", 1, 20);
width=getvalue("\nEnter the width of the prism: ", 1, 20);
height=getvalue("\nEnter the height of the prism: ", 1, 20);
calcPrism (length, width, height);
}
choice=menu();
if (choice=3)
{
radius=getvalue("\nEnter the radius of the cone: ", 1,7);
length=getvalue("\nEnter the length of the cone: ", 1, 12);
calcCone (radius, length);
}
choice=menu();
if (choice=4)
{
length=getvalue("\nEnter the length of the pyramid: ", 1, 10);
height=getvalue("\nEnter the height of the pyramid: ", 1, 15);
calcPyramid (length, height);
}
}
return 0;
}