There were a couple of things I changed:
1.) after debugging of the code I noticed that there is no difference of results, whether I provide 3.5 or 3 as height or radius
2.) sphereVolume: did not return a value
3.) cubeVolume: did not return a value
4.) too many brackets
5.) I ommitted Svolume and Cvolume variables, because they are not needed in the current context. It could have been though that you introduced those variables in order to use them later on elsewhere. So I could very well be considered ignorant here.
6.) I changed the wording of your choice prompt. I believe it helps guide the user, now, but I may be considered ignorant (i.e. of your assignment)
7.) With my compiler I could not duplicate a "NaN" result. NaN stands for Not a Number.
8.) The assignment shape='a' I took from the if condition to the end of the loop.
I did this for the following reasons:
a) code reduction
b) increase code transparency
Your approach could be considered speed optimized and my change ignorant to that intent
9) I changed the nesting of your if statements. I believe they meet your requirements and are easier to understand, now
#include
using namespace std;
double sphereVolume(int r);
int cubeVolume(int);
int main()
{
char shape= 'a';
int h = 0; // initialized
int r = 0; // initialized
// double Svolume = 0.0; // initialized - not needed
// int Cvolume; // initialized - not needed
while (!(shape=='s' || shape=='c' || shape == 'q')) {
cout<<"s sphere volume\nc cube volume\nq quits > ";
cin>> shape;
shape = tolower(shape);
if (shape== 's')
{
cout< ";
cin>> r;
cout<
}
else if (shape== 'c')
{
cout< ";
cin>> h;
cout<< endl<<"The volume is "<< cubeVolume(h)<
}
else if (shape== 'q') {
break;
}
else {
cout << "Input not recognized " << endl;
}
shape = 'a'; // initialize shape in the loop
cin.ignore();
}
system("pause");
return 0;
}
double sphereVolume(int r)
{
return 1.34*3.14*r*r*r;
}
int cubeVolume(int h)
{
return h * h * h;
}