what's wrong with this code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <sstream>


using namespace 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.
Last edited on
you're missing a semicolon after your class declaration.
fixed it i still got an error something is wrong can anyone tell me waht is it? i
What's your error, where do you think it is?
i dont' nkow ti give me a near infinite line of error. jsut put in a compiler and run it u'll know it.
Hahaha I'm trying to get you to look at it ;) I'm not going to do that much work.
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)"
Last edited on
Not what I'm saying =) I'm just saying me compiling it is too much work for me =)
1
2
	char getFirstname (void) {return Firstname[20];}
	char getLastname (void) {return Lastname[20];}


This doesn't do what you think it does.

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
Last edited on
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;

by using "class"
Last edited on
1
2
3
4
5
6
7
8
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.
ok, so u are telling me i need a
void setname (char Firstname) and ste a default constructor?
@hunkeelin : i think you should like this code !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include <sstream>


using namespace 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");
	
}
Last edited on
Topic archived. No new replies allowed.