-
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.
-
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;
}
-
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.