GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Feb-2010, 21:40
MTW1989 MTW1989 is offline
New Member
 
Join Date: Feb 2010
Posts: 15
MTW1989 has a little shameless behaviour in the past

Two or more data types in declaration error


I keep getting the above error code when trying to execute to following source code:

CPP / C++ / C Code:
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

void double areasquare(double& length);

void double areacircle(double& radius, double& PI);

void double arearectangle(double& lengthtwo, double& width);

void getUserInput (char& Y);

void output(double);

void outputelse ();

void functionfrommain ();

void validshapes ();

int main(int argc, char *argv[])
{
    const double PI = 3.14159;
    double radius, length, width, lengthtwo;
    char Y;
    char S;
    char C;
    char R;
    
    functionfrommain ();
    
    getUserInput(Y);
    
    if (Y == 'Y' || Y == 'y');
    cin >> Y;
    
  do
  {   
     length = 0;
     lengthtwo = 0;
     width = 0;
     radius = 0; 
      
     validshapes (); 
     
     cout << "Enter the proper letter : " << endl;
     
    if (S == 'S' || S == 's')
    {
          cout << "Enter length of one side of the square : " << endl;
          cin >> length;
          cout << setiosflags(ios::fixed)
          << setprecision(2);
          cout << areasquare ();
    }      
    else if (C == 'C' || C =='c')
    {
          cout << "Enter the radius of the circle : " << endl;
          cin >> radius;
          cout << setiosflags(ios::fixed)
          << setprecision(2);
          cout << areacircle ();
    }
    else if (R == 'R' || R =='r')
    {
          cout << "Enter the length of the rectangle : " << endl;
          cin >> lengthtwo;
          cout << "Enter the width of the rectangle : " << endl;
          cin >> width;
          cout << setiosflags(ios::fixed)
          << setprecision(2);
          cout << arearectangle ();  
    }
 }     
  while(S == 'S' || S == 's') || (C == 'C' || C =='c') || (R == 'R' || R =='r');
 
 else
 {
     outputelse ();
 }
     

    system("PAUSE");
    return EXIT_SUCCESS;
}

void getUserInput (char& Y)
{
      cout << "Enter Y to continue anything else to stop : " << endl;            
      cin >> Y;
}

void areasquare (double& length)
{
    length*length
}

void areacircle (double& radius)
{
     PI*radius*radius
}

void arearectangle (double& lengthtwo, double& width)
{
    lengthtwo*width
}

void outputelse ()
{
     cout << "Thank you for using the Area Calculator Service." << endl;
}

void functionfrommain ()
{
      cout << "This program the area for a user specified geometric shape. \
      You will be asked to enter a code representing the shape. Depending on your choice,\
      the program will prompt you for additional information necessary to calculate the area." << endl;
      
      cout << "You will be asked if you want to enter <more> data. \
      Follow the directions provided to either stop the program or continue." << endl;
      
      cout << "Do you want to <enter> more data ?" << endl;
}      
      
      
void validshapes ()      
{
  cout <<  "-- VALID SHAPES --" << endl;
  cout << "Enter S for square \
           Enter C for circle \
           Enter R for rectangle" << endl;   
}

how can i fix this error, there are only doubles used in areacircle, areasquare, arearectangle.
Last edited by LuciWiz : 23-Feb-2010 at 23:57. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 23-Feb-2010, 22:29
MTW1989 MTW1989 is offline
New Member
 
Join Date: Feb 2010
Posts: 15
MTW1989 has a little shameless behaviour in the past

Re: Two or more data types in declaration error


no one?
bump
  #3  
Old 23-Feb-2010, 22:46
Kimmo Kimmo is offline
Regular Member
 
Join Date: Mar 2007
Location: Finland
Posts: 450
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: Two or more data types in declaration error


Quote:
Originally Posted by MTW1989
no one?
bump
Are you honestly saying you don't see multiple types at any of these lines?

CPP / C++ / C Code:
void double areasquare(double& length);

void double areacircle(double& radius, double& PI);

void double arearectangle(double& lengthtwo, double& width);

Also, don't bump. Suddenly I don't feel that helpful.
  #4  
Old 24-Feb-2010, 04:00
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 656
Mexican Bob is just really niceMexican Bob is just really niceMexican Bob is just really niceMexican Bob is just really nice

Re: Two or more data types in declaration error


Quote:
Originally Posted by Kimmo
Are you honestly saying you don't see multiple types at any of these lines?

CPP / C++ / C Code:
void double areasquare(double& length);

void double areacircle(double& radius, double& PI);

void double arearectangle(double& lengthtwo, double& width);

Also, don't bump. Suddenly I don't feel that helpful.


Kimmo's help should be obvious, however, sometimes it is the most obvious things that we can't find.

Perhaps a question?

How can a function return both a "void" and a "double" at the same time?


MxB
  #5  
Old 24-Feb-2010, 06:01
Kimmo Kimmo is offline
Regular Member
 
Join Date: Mar 2007
Location: Finland
Posts: 450
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: Two or more data types in declaration error


Quote:
Originally Posted by Mexican Bob
...sometimes it is the most obvious things that we can't find.
You're right, perhaps it was too harsh. It's more than once I've tried to locate weird bugs when I wrote =! instead of !=, myself.

But bumping threads after 50 minutes as if we have no life at all is sometimes too much to take.

Anyway... After taking a longer look at your code I feel like you might be better of starting the whole thing from scratch. Or you might not, it probably depends on what your aim is with this. A few things I noticed by looking at it:

CPP / C++ / C Code:
void getUserInput (char& Y);
Passing by reference is a great feature, but there are times when it makes more sense / is more intuitive to return a value instead. I feel this is one of those cases. A char as a type is so small it makes practically no difference to just return a char. Returning a value allows for easier comparison:

CPP / C++ / C Code:
if (functionThatReturns())
    // do something


CPP / C++ / C Code:
void outputelse ();

void functionfrommain ();
These function names aren't very meaningful. Personally I would interpret 'functionfrommain()' as some kind of a main loop of your application. I would strive for meaningful names in everything from the start.

CPP / C++ / C Code:
void validshapes ();
Again, a personal preference, but I like to see 'print' or some other indication of printing if a function is supposed to print. 'validshapes()' to me is an indication that this returns some kind of a list of all the valid shapes.

CPP / C++ / C Code:
    double radius, length, width, lengthtwo;
See, meaningful names. Now everyone knows what they're supposed to be used for.

CPP / C++ / C Code:
    getUserInput(Y);
    
    if (Y == 'Y' || Y == 'y');
    cin >> Y;
This body of if should probably do something else? If the user enters 'y' or 'Y', you should probably just continue, not wait for more input. Perhaps a more meaningful test would be to test if the user entered 'n' or 'N'? Then you could just quit.

Also note that your have a semicolon after the closing brace for if. That makes this equal to

CPP / C++ / C Code:
if (Y == 'Y' || Y == 'y')
{

}
cin >> Y;
That is, the "cin >> Y;" is not inside the if body.

CPP / C++ / C Code:
  while(S == 'S' || S == 's') || (C == 'C' || C =='c') || (R == 'R' || R =='r');
You are probably missing one opening brace here. It would seem you meant
CPP / C++ / C Code:
while ((S == 'S' || S == 's') || (C == 'C' || C =='c') || (R == 'R' || R =='r'));

CPP / C++ / C Code:
    system("PAUSE");
Run your programs from the command line and you won't need this. And non-Windows / non-MS-DOS users will thank you?

CPP / C++ / C Code:
void areacircle (double& radius)
{
     PI*radius*radius
}
Note that you declared PI inside main(). That means the scope of PI is the main() function. The scope doesn't extend to functions you call from inside main(), thus PI is not visible inside this function.

CPP / C++ / C Code:
void functionfrommain ()
{
      cout << "This program the area for a user specified geometric shape. \
      You will be asked to enter a code representing the shape. Depending on your choice,\
      the program will prompt you for additional information necessary to calculate the area." << endl;
      
      cout << "You will be asked if you want to enter <more> data. \
      Follow the directions provided to either stop the program or continue." << endl;
      
      cout << "Do you want to <enter> more data ?" << endl;
}      
Perhaps a more meaningful name for this would be something like 'printWelcome()' ?



Are you really supposed to use all those functions? I mean, many seem like they are there just for the sake of having functions.
  #6  
Old 24-Feb-2010, 07:47
MTW1989 MTW1989 is offline
New Member
 
Join Date: Feb 2010
Posts: 15
MTW1989 has a little shameless behaviour in the past

Re: Two or more data types in declaration error


Ya the code does kinda seem like a big ol' mess maybe i'll start from scratch, but thank you your input ill be sure to incorporate that into the next set of code.
  #7  
Old 24-Feb-2010, 13:02
MTW1989 MTW1989 is offline
New Member
 
Join Date: Feb 2010
Posts: 15
MTW1989 has a little shameless behaviour in the past

Re: Two or more data types in declaration error


I re-did the code up to this point and am now lost;

CPP / C++ / C Code:
#include <cstdlib>
#include <iostream>
#include <iomanip>


using namespace std;

void functionfrommain ();

void getUserInput (char& Y);

void validshapes ();

void areacalculations (char& S, char& C, char& R, double& length, double& radius, double& lengthtwo, double& width);

int main(int argc, char *argv[])
{
    char Y = Y;
    char S = S;
    char C = C;
    char R = R;
    const double PI = 3.14159;
    double length; double radius; double lengthtwo; double width;
    
    functionfrommain ();
    
    getUserInput (Y);
    
      if (Y == 'Y' || Y == 'y')
      {
       validshapes ();
      }

      else
      {
       cout << "Thank you for using the Area Calculator Service." << endl;
      }

 do 
 {
     double length = 0;
     double radius = 0;
     double lengthtwo = 0;
     double width = 0;
     
     areacalculations (S, C, R, length, radius, lengthtwo, width);
 }

 while ((S == 'S' || S == 's') || (C =='C' || C == 'c') || (R =='R' || R == 'r'));  
      
    
    system("PAUSE");
    return EXIT_SUCCESS;
}



     void functionfrommain ()
     {
     
      cout <<"This program the area for a user specified geometric " << endl;
      cout << "shape. You will be asked to enter a code representing the shape. " << endl;
      cout <<"Depending on your choice,the program will prompt you for " << endl;
      cout  <<"additional information necessary to calculate the area. " << endl;
      cout  <<"                                                        " << endl;
      
      cout <<"You will be asked if you want to enter <more> data. " << endl;
      cout <<"Follow the directions provided to either stop the program or continue." << endl;
      cout <<"                                                                      " << endl;
      

      cout << "Do you want to <enter> more data ?" << endl;
      } 
      
      void getUserInput (char& Y)
      {
      cout << "Enter Y to continue anything else to stop: ";            
      cin >> Y;
      cout << "                                            " << endl;
      }   
      void validshapes ()   
      {
      cout << setw(5) << "-- VALID SHAPES --" << endl;
      cout << setw(5) << "Enter S for square" << endl;
      cout << setw(5) << "Enter C for circle" << endl; 
      cout << setw(5) << "Enter R for rectangle" << endl;   
      }   
      
      void areacalculations (char& S, char& C, char& R, double& length, double& radius, double& lengthtwo, double& width)
      {  
        const double PI = 3.14159;   
           
        if (S == 'S' || S == 's')
        {
        cout <<"Enter the length of 1 side of the square: "<< endl;
        cin >> length;
        cout <<"The area of your square is:" << length*length << endl;
        cout << setiosflags(ios::fixed)
             << setprecision(2);
        }   
       else if (C =='C' || C == 'c')
       {
       cout <<"Enter the radius of the circle : " << endl;
       cin >> radius;
       cout <<"The area of your circle is:" << PI*radius*radius << endl;
       cout << setiosflags(ios::fixed)
            << setprecision(2);
       }
       else if (R =='R' || R == 'r')
       {
       cout <<"Enter the length of the rectangle : " << endl;
       cin >> lengthtwo;
       cout << "Enter the width of the rectangle : " << endl;
       cin >> width;
       cout << "The area of your rectangle is:" << lengthtwo*width << endl;
       cout << setiosflags(ios::fixed)
            << setprecision(2);
       }     
       
}

It runs but after I input Y it prints validshapes, and then stops. I dont know If i am leaving something out, but the program stops at this function

CPP / C++ / C Code:
 if (Y == 'Y' || Y == 'y')
      {
       validshapes ();
      }

      else
      {
       cout << "Thank you for using the Area Calculator Service." << endl;
      }
it doesnt read anything after this point.
Last edited by admin : 14-Jun-2012 at 10:02. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #8  
Old 24-Feb-2010, 14:32
MTW1989 MTW1989 is offline
New Member
 
Join Date: Feb 2010
Posts: 15
MTW1989 has a little shameless behaviour in the past

Re: Two or more data types in declaration error


----end thread----
  #9  
Old 13-Jun-2012, 16:08
faithword faithword is offline
New Member
 
Join Date: May 2012
Posts: 5
faithword is on a distinguished road

Re: Two or more data types in declaration error


Did you get this to work? I am doing this same assignment.
  #10  
Old 14-Jun-2012, 06:37
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Regular Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 656
Mexican Bob is just really niceMexican Bob is just really niceMexican Bob is just really niceMexican Bob is just really nice

Re: Two or more data types in declaration error


Quote:
Originally Posted by faithword
Did you get this to work? I am doing this same assignment.

Does any body know what the assignment is? The assumption that it must calculate the area of various shapes is fairly obvious, but are there any "rules" or other requirements?

The code presented here is not horrible, considering that it is from someone just learning the language, but it is fairly awful. I'd suggest that you look at it as an example of what not to do.


MxB
 
 

Recent GIDBlogRunning Linux Programs at Boot Time by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling C btrieve programs in VS 2005 emanresu C Programming Language 1 16-Nov-2009 03:19
Error C2143: syntax error : missing ';' before '.' kiranpreddy05 MS Visual C++ / MFC Forum 1 05-Nov-2009 07:39
Memory leak when nothing is happening... How can I even debug this ? Algar MS Visual C++ / MFC Forum 10 19-Nov-2007 07:17
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:09.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.