#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
class player
{
private:
char Firstname[20];
char Lastname[20];
float R;
float G;
float RPG;//rebound per game
void calcRPG(void){RPG = (R / G);}//rebound per game
public:
char getFirstname (void) {return Firstname[20];}
char getLastname (void) {return Lastname[20];}
float getrebounds (void) {return R;}
float getRPG (void) {return RPG;}
};
int main()
{
player keith;
cout<<"enter first name";
cin>>keith.getFirstname();
cout<<"the name of the player is"<<keith.getFirstname();
cout<<"enter player rebounce";
cin>>keith.getrebounds();
cout<<"enter player games played";
cin<<keith.getrebounds();
cout<<"the rebounce per game for p[layer keith is"<<keith.getRPG;
}
i just want to display the name of the player and the rebound per game but somehow it gave me a strange error. i msut use a class private and public.
oh wait, so ur telling me i'm VERY wrong in a way that you need to do "much work" to fix it? S=
Ok, let me put it this way (i fix my code)
do
player keith
cout<<"enter first name";
cin>>keith.getFirstname;
cout<<"the name of the player is"<<keith[0].getFirstname;
display the first name? i mean i somehow can't make it wrok i just want to know the way to store and display a value/anything in a class.
the error i have is something i never seen before
"spring 2010\cmpsc\cmpsc 122\cpp2_1111\cpp2_1111\cpp2_1.cpp(67): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)"
panGalactic Ok, now that's a start so what's wrong with those 2 lines? what i want is the getFirstname return to Firstname and it's exactly what i did and what's wrong with it?
i try
char getFirstname (void) {return Firstname;}
char getLastname (void) {return Lastname;}
which doesn't work (since there's a red line under it)
char getFirstname (void) {return Firstname[];}
char getLastname (void) {return Lastname[];}
which give me a read line under it too
ehh ok i'm getting nowhere, can you send me a link of a sample code that the code itself is a class and it makes user input stuff and display it in a function?
Or just tell me
what is
char name;
cout<<"what's your name"
cin>>name;
cout<<""your name is"<<name;
cout<<"enter first name";
cin>>keith.getFirstname();
cout<<"the name of the player is"<<keith.getFirstname();
cout<<"enter player rebounce";
cin>>keith.getrebounds();
cout<<"enter player games played";
cin<<keith.getrebounds();
The error is telling you there is a problem with your cin usage. You are trying to put a value from cin into a function thats RETURNING a value. you need to write setter methods.
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
class player
{
private:
char Firstname[20];
char Lastname[20];
float R;
float G;
public:
void getFirstname ()
{
cout<< " enter first name : ";
cin.getline(Firstname,20);
fflush(stdin);
cout<<" Enter player rebounce : ";
cin>>R;
cout<<" Enter player the played : ";
cin>>G;
}
float getRPG ()
{
return (R/G);
}
};
int main()
{
player keith;
keith.getFirstname();
cout<<"the rebounce per game for p[layer keith is: "<<keith.getRPG()<<endl;
system ("pause");
}