0
find error in this program
#include<iostream> using namespace std; class player { char pname; int avg; char pteam; public: void input() { cout<<"enter player name:"<<endl; cin>>pname; cout<<"enter average:"<<endl; cin>>avg; cout<<"enter team"<<endl; cin>>pteam; } void output() { cout<<"player name is:"<<pname<<endl; cout<<"average is"<<avg<<endl; cout<<"player team is"<<pteam<<endl; } }; int main() { player p; p.input(); p.output(); return 0; }
9 Respuestas
+ 3
There is no error 🤔
Maybe you wanted to use string instead of char?
+ 2
Omkar was right, you could've used string instead of char. Being as it is now, you will only keep the first character of <pname> and <pteam> value.
Please tag a relevant language -> C++ 👍
0
I dont know
but this program is not giving correct output
0
You have a new line character '\n' left on the input stream after reading <pname>. To overcome this problem you can add ...
cin.ignore(); // discard the '\n'
cin.clear(); // reset stream state
Just before you read <avg>.
P.S. You still don't have C++ in thread tags ☝
0
declare pname and pteam as array type like pname[5] and pteam[5]
0
Your pname and pteam are not arrays
0
You have to use String instead of Char
0
#include<iostream.h>
Using namespace std;
class player
{
Private:
char pname[20];.
char pteam[20];.
int avg;
0
Here access specifier private:
Is missed