First Time Posting Sorry

I needed to create a volume program, pretty simple. But I find two errors, in my while loop and in my case statement. If someone can guide me to, how to ask for one shape, then another, and how to I get the program to exit after Q is entered. Thanks.

#include <iostream>
using namespace std;

//Use Float?
double volCone (float r, float h){
float vc;
vc = (1.0/3.0)*(3.14)*(r*r)*(h);
return (vc);
}

double volCube(double a){
int vcu;
vcu = (a*a*a);
return (vcu);
}

double volCylinder(float r,float h){
float vcy;
vcy = (3.14)*(r*r)*(h);
return (vcy);
}

double volPyramid(float a, float h){
float vp;
vp = (1.0/3.0)*(a*a)*(h);
return (vp);
}

double volSphere(float r){
float vs;
vs = (4.0/3.0)*(3.14)*(r*r*r);
return (vs);
}

int main () {
cout << "Hello, welcome to the shape volume computing program." << endl;
cout << "Which shape do you have?" << "\nC for Cone" << "\nU for Cube" << "\nY for Cylinder" << "\nP for Pyramid" << "\nS for Sphere" << "\nQ to Quit\n" << endl;

float dim, rad, hat, sid;
char shape;
cin >> shape;
while (shape != 'Q' || 'q') {



switch (shape) {

case 'c':
case 'C':
cout << "You entered Cone. Please enter the dimensions.\nEnter the radius. ";
cin >> rad;
cout << "Enter the height. ";
cin >> hat;
cout << "Radius = " << rad << " and Height = " << hat << ".";
dim = volCone (rad, hat);
cout << "\nVolume of Cone = " << dim << "\n";
break;

case 'u':
case 'U':
cout << "You entered Cube. Please enter the dimensions. \nEnter the side. ";
cin >> sid;
cout << "Length of side = " << sid;
dim = volCube (sid);
cout <<"\nVolume of Cube = " << dim << "\n";
break;

case 'y':
case 'Y':
cout << "You entered Cylinder. Please enter the dimensions. \nEnter the radius. ";
cin >> rad;
cout << "Enter the height. ";
cin >> hat;
cout << "Radius = " << rad << " and Height = " << hat << ".";
dim = volCylinder (rad, hat);
cout <<"\nVolume of Cylinder = " << dim << "\n";
break;

case 'p':
case 'P':
cout << "You entered Pyramid. Please enter the dimensions. \nEnter the side.";
cin >> sid;
cout << "Enter the height.";
cin >> hat;
cout << "Lenth of the side = " << sid << " and Height = " << hat;
dim = volPyramid (sid, hat);
cout << "\nVolume of Pyramid = " << dim << "\n";
break;

case 's':
case 'S':
cout << "You entered Sphere. Please enter the dimensions. \nEnter the radius.";
cin >> rad;
cout << "The radius = " << rad << "\n";
dim = volSphere (rad);
cout << "Volume of Sphere = " << dim << "\n";
break;



}//End Switch




}//End While Loop
return 0;
}
Sorry but this would go to the beginner section. And why are you doing all those returns that are pointless?
Post the code in the "<>" tags from the Format menu it makes easier for us to read and understand the code.

What are the errors that you are getting? Post any compiler errors as well.

I see while (shape != 'Q' || 'q') { that should be while (shape != 'Q' || shape != 'q') {
Sorry about that Maxim, my first time posting.
And Thanks Codewalker, the error I am getting is that:
When a shape such as C is entered. It will loop back that shape C.
Topic archived. No new replies allowed.