Frustrating Error

This is a discussion on Frustrating Error within the C++ Programming forums, part of the General Programming Boards category; Hey! Thanks in advance for trying to help! Anyways, I have a ";" error that keeps flashing up. Wrestling.cpp(46) : ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    Exclamation Frustrating Error

    Hey! Thanks in advance for trying to help! Anyways, I have a ";" error that keeps flashing up.

    Wrestling.cpp(46) : error C2146: syntax error : missing ';' before identifier 'cout'

    And I swear I have a semicolon before the line. So I'm hoping you guys can help this newbie out.

    Here is the code:

    (I've underlined the line that needs a semicolon before it)

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    struct person
    {
    	double name;
    	int weight;
    };
    
    void getwrestlerdata(struct person &);
    void printwrestlerdata(struct person);
    int main()
    {
    	person wrestler;
    	getwrestlerdata(wrestler);
    	printwrestlerdata(wrestler);
    
    	return 0;
    }
    
    
    void getwrestlerdata(struct person &s)
    {
    	cout<<"Please enter student's name\n";
    	cin>>s.name;
    
    	cout<<"Please enter student's weight(in pounds)\n";
    	cin>>s.weight;
    
    return;
    }
    
    void printwrestlerdata(struct person s)
    {
    	cout<<s.name<<", who weighs "<<s.weight<<", is classified as a ";
    
    	if(s.weight<100)
    		cout<<"lightweight. "<<endl;
    
    	else if(s.weight>99 && s.weight<200)
    		cout<<"middleweight. ";
    
    	else(s.weight>200)
    		cout<<"heavyweight."<<endl;
        
    	return;
    }
    Its really frustrating me...

    I just don't understand what I'm doing wrong.
    Last edited by ZWarren69; 11-18-2005 at 12:55 AM.

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    here's is the corrected code...see the changes in bold
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    struct person
    {
    	char name[20];
    	double weight;
    };
    
    void getwrestlerdata(struct person &);
    void printwrestlerdata(struct person);
    int main()
    {
    	person wrestler;
    	getwrestlerdata(wrestler);
    	printwrestlerdata(wrestler);
    
    	return 0;
    }
    
    
    void getwrestlerdata(struct person &s)
    {
    	cout<<"Please enter student's name\n";
    	cin>>s.name;
    
    	cout<<"Please enter student's weight(in pounds)\n";
    	cin>>s.weight;
    
    return;
    }
    
    void printwrestlerdata(struct person s)
    {
    	cout<<s.name<<", who weighs "<<s.weight<<", is classified as a ";
    
    	if(s.weight<100)
    		cout<<"lightweight. "<<endl;
    
    	else if(s.weight>99 && s.weight<200)
    		cout<<"middleweight. ";
    
    	else if(s.weight>200)
    		cout<<"heavyweight."<<endl;
        
    	return;
    }

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    10
    Or better still:

    Code:
    struct person
    {
    	string name;
    	double weight;
    };
    char name[20]; defines a character array with space for twenty individual characters; if you enter a name which has more than twenty characters (unlikely in this case admittedly), the characters beyond the twentieth will not be stored in the array. A string is able to expand to however many characters are entered, and thus does not suffer this problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21