Join 136,103 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,696 people online right now. Registration is fast and FREE... Join Now!
switch (answer) { case 1: { cout<<"Please enter the lenght and width of the box:"<<endl; cin>>length>>width; cout<<endl; float volbox (float length, float width); } break; case 2: { cout<<"Please enter the radius of the sphere:"<<endl; cin>>radius; cout<<endl; float volsphe (float radius); } break; case 3: { cout<<"Please enter the radius and height of the cylinder:"<<endl; cin>>radius>>height; cout<<endl; float volcyl (float radius, float height); } break; case 4: { cout<<"Please enter the base and height of the pyramid:"<<endl; cin>>base>>height; cout<<endl; float volpyr (float base, float height); } break; default: answer =; ***************************************error 1******************* } disp_out (int& answer, float& volume, float& length, float& width, float& radius, ******error 2 and 3******************* float& height, float& base); *****error 4************************ return 0; }
//====================== sel_shape ============================= // Prompt user from menu to select a shape // pre none // post answer int sel_shape (void) { int answer = 0;
do { cout<<"For what shape do you want to calculate the volume?/n"; cout << "(Press: 1 for box, 2 for sphere, 3 for cylinder, and 4 for pyramid)"<<endl; cin>>answer; if (answer <1 || answer >4) cout<<endl<<"You have entered an invalid number. Please try again"<<endl; } while ((answer <1 || answer >4));
return answer; } //================ cal_volbox ==================== // Calculate the volume for a box // pre lenght, width // post volume
float volbox (float &l, float &w) { float volume; volume = l*w; return volume; } //================ calc_volsphe ==================== // Calculate the volume for a sphere // pre radius // post volume
float volsphe (float &r) { float volume; volume = (4*pi*r*r*r)/3; return volume; } //================ cal_volcyl==================== // Calculate the volume for a cylinder // pre radius, height // post volume
float volcyl (float r, float h) { float volume; volume = pi*r*r*h; return volume; } //**================ cal_volpyr==================== // Calculate the volume for a pyramid // pre base, height // post volume
float volpyr (float &b, float &h) { float volume; volume = (b*b*h)/3; return volume; } //**================ disp_out==================== // Calculate the volume for a pyramid // pre length, width, radius, height, base // post none void disp_out (int& answer, float& volume, float& l, float& w, float& r, float& h, float& b) { cout<<"The Volume for "; switch (answer) { case 1: {cout<<"a box with lenth "<<l<<" and width"<<w<<" is:"<<endl; cout<<volume; } break; case 2: {cout<<"sphere with a radius of "<<r<<" is:"<<endl; cout<<volume; } break; case 3: {cout<<"a cylinder with a radius of"<<r<<" and height"<<h<<" is:"<<endl; cout<<volume; } break; case 4: {cout<<"a pyramid with a base of "<<b<<" and height"<<h<<" is:"<<endl; cout<<volume; } break; }
return (); }
This post has been edited by complexc25: 14 Oct, 2007 - 06:33 PM
and you also shouldn't have this statement in your last function: return (); the function will return to the calling routine automatically, so you don't need to force it. and if you want to force a return for some reason (conditional execution of code or something like that), you can just use return; with no parentheses and no return argument - returning ( ) is likely causing one of your errors.
sorry for not pointing out whre the errors are.... the errors are where the asterisk lines are in the code. NickDMax, I fix that, thanx for pointing it out. Also i removed the return (); line from the code like jjhagg. Still though, im getting the same errors
//====================== Main =============================== int main () { //local declarations int answer; float volume, length, width, radius, height, base; //Statements answer = sel_shape(); cout<<answer;
switch (answer) { case 1: { cout<<"Please enter the lenght and width of the box:"<<endl; cin>>length>>width; cout<<endl; volume = volbox (length, width); } break; case 2: { cout<<"Please enter the radius of the sphere:"<<endl; cin>>radius; cout<<endl; volume = volsphe (radius); } break; case 3: { cout<<"Please enter the radius and height of the cylinder:"<<endl; cin>>radius>>height; cout<<endl; volume = volcyl (radius, height); } break; case 4: { cout<<"Please enter the base and height of the pyramid:"<<endl; cin>>base>>height; cout<<endl; volume = volpyr (base, height); } break; default: answer =; } disp_out (int& answer, float& volume, float& length, float& width, float& radius, float& height, float& base); return 0; }
//====================== sel_shape ============================= // Prompt user from menu to select a shape // pre none // post answer int sel_shape (void) { int answer = 0;
do { cout<<"For what shape do you want to calculate the volume?/n"; cout << "(Press: 1 for box, 2 for sphere, 3 for cylinder, and 4 for pyramid)"<<endl; cin>>answer; if (answer <1 || answer >4) cout<<endl<<"You have entered an invalid number. Please try again"<<endl; } while ((answer <1 || answer >4));
return answer; } //================ cal_volbox ==================== // Calculate the volume for a box // pre lenght, width // post volume
float volbox (float &l, float &w) { float volume; volume = l*w; return volume; } //================ calc_volsphe ==================== // Calculate the volume for a sphere // pre radius // post volume
float volsphe (float &r) { float volume; volume = (4*pi*r*r*r)/3; return volume; } //================ cal_volcyl==================== // Calculate the volume for a cylinder // pre radius, height // post volume
float volcyl (float r, float h) { float volume; volume = pi*r*r*h; return volume; } //**================ cal_volpyr==================== // Calculate the volume for a pyramid // pre base, height // post volume
float volpyr (float &b, float &h) { float volume; volume = (b*b*h)/3; return volume; } //**================ disp_out==================== // Calculate the volume for a pyramid // pre length, width, radius, height, base // post none void disp_out (int& answer, float& volume, float& l, float& w, float& r, float& h, float& b) { cout<<"The Volume for "; switch (answer) { case 1: {cout<<"a box with lenth "<<l<<" and width"<<w<<" is:"<<endl; cout<<volume; } break; case 2: {cout<<"sphere with a radius of "<<r<<" is:"<<endl; cout<<volume; } break; case 3: {cout<<"a cylinder with a radius of"<<r<<" and height"<<h<<" is:"<<endl; cout<<volume; } break; case 4: {cout<<"a pyramid with a base of "<<b<<" and height"<<h<<" is:"<<endl; cout<<volume; } break; }
}
This post has been edited by complexc25: 14 Oct, 2007 - 06:32 PM
if you've editted the code you first posted, you don't appear to have taken NickDMax's advice. for instance, the line float volbox (float length, float width); in your first case block is incorrect. if you are trying to call this function and assign the result to a variable volume, you need to declare the variable volume before the switch-case control statements.
if you haven't editted the code in your first post, please post an updated version of your code. leave the previous posts as they are, and we can take a look at the new stuff.