Welcome to Dream.In.Code
Getting C++ Help is Easy!

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!




help with 4 errors

 
Reply to this topicStart new topic

help with 4 errors

complexc25
14 Oct, 2007 - 01:40 PM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 13


My Contributions
Can anyone help me fix the errors in this program i made. I am confused about them. Thanx in advanced.

These are the Errors:

error C2059: syntax error : ';'
error C2144: syntax error : missing ')' before type 'int'
error C2660: 'disp_out' : function does not take 0 parameters
error C2059: syntax error : ')'
error C2059: syntax error : ')'[/code]

CODE

#include <iostream.h>
#include <string.h>

const float pi = 3.14159;


int sel_shape (void);

float volbox (float& length, float& width);
float volsphe (float& radius);
float volcyl (float& radius, float& height);
float volpyr (float& base, float& height);
void disp_out (int& answer,  float& volume, float& length, float& width,
               float& radius, float& height, float& base);
//======================   Main   ===============================
int main ()
{
    //local declarations
    int answer;
    float 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;
          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
User is offlineProfile CardPM
+Quote Post

zandiago
RE: Help With 4 Errors
14 Oct, 2007 - 02:04 PM
Post #2

D.I.C Head
**

Joined: 13 Jul, 2007
Posts: 190


My Contributions
perhaps if you told us which lines your compiler say...it's much easier to solve it that way.

CODE

while ((answer <1 || answer >4));
I think that DOES NOT need a semicolon at the end.

This post has been edited by zandiago: 14 Oct, 2007 - 02:04 PM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Help With 4 Errors
14 Oct, 2007 - 04:56 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
I seem to remember answering a very similar question from you this morning.

When you use a function, you just need to pass the data not the data-type (unless you are typecasting which you are not).

so,

float volbox (float length, float width);
would be something like
volume = volbox (length, width);

notice that there is a return value, and that I don't precede the length and with with "float"

You have to change almost every function call you have in the program.


BTW the semi-colon does belong at the end of the do-while loop.
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Help With 4 Errors
14 Oct, 2007 - 05:09 PM
Post #4

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
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.

-jjh
User is offlineProfile CardPM
+Quote Post

complexc25
RE: Help With 4 Errors
14 Oct, 2007 - 05:44 PM
Post #5

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 13


My Contributions
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
CODE

#include <iostream.h>
#include <string.h>

const float pi = 3.14159;


int sel_shape (void);
float volbox (float& length, float& width);
float volsphe (float& radius);
float volcyl (float& radius, float& height);
float volpyr (float& base, float& height);
void disp_out (int& answer,  float& volume, float& length, float& width,
               float& radius, float& height, float& base);

//======================   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
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Help With 4 Errors
14 Oct, 2007 - 06:07 PM
Post #6

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
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.

-jjh

User is offlineProfile CardPM
+Quote Post

complexc25
RE: Help With 4 Errors
15 Oct, 2007 - 04:22 AM
Post #7

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 13


My Contributions
guys i think i found out where the problem was. Instead of:
CODE
         answer =;
    }
disp_out (int& answer,  float& volume, float& length, float& width, float& radius,
          float& height, float& base);
return 0;
}

it should be:
CODE
  answer =;
    }
disp_out (answer,  volume, length, width, radius, height, base);
return 0;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:03PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month