i'm trying to run a program that calculates the surface area of various shapes. right now i only have it set it up through a sphere, but i can't go further until i figure this out. part of the assignment is that i must use the function "int getValue (string prompt, lowerBound, upperBound". so when this function is used, it will enter some words, in this case, something like "enter the radius of the sphere, and then there are limits as to how small and how large the radius can be. 2-15, let's say. anything outside that range is invalid and the user needs to be asked to try again. i've tried implementing this function a few different ways but it keeps being skipped completely. here is my code (i'm focusing on this function, not worried about the neatness of the rest of the code right now)
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
const double PI = 3.14159;
int value,choice, radius;
float surface_area_sphere;
int menu(int choice)
{
cout<<"\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)
{
cin>>radius;
surface_area_sphere=(4*PI*radius*radius);
cout<<"The surface area of the sphere is"<<surface_area_sphere;
return (surface_area_sphere);
};
int getValue (string prompt, int lowerBound, int upperBound)
{
return (lowerBound-upperBound);
};
int main()
{
menu(choice);
{
if (choice=1)
getValue ("Enter the radius of the sphere", 2,15);
calcSphere (radius) ;
}
}
so i want the getValue function, when the user enters 1 for choice, to prompt them to enter the radius, and then have to enter one between 2 and 15. but when i run this, it runs the menu function fine, then skips the get value, and goes to calcSphere, where i can enter a number (without any prompting though) and it calculates it fine. i don't understand the purpose of the getValue function and it seems like it's unnecessary to me, but i have to use it. any advice on how to get it to work?
return 0;
}