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

27th Mar 2020, 9:47 AM
Haider Ali
9 Respostas
+ 3
There is no error đŸ€” Maybe you wanted to use string instead of char?
27th Mar 2020, 9:52 AM
🇼🇳Omkar🕉
🇼🇳Omkar🕉 - avatar
+ 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++ 👍
27th Mar 2020, 10:00 AM
Ipang
0
I dont know but this program is not giving correct output
27th Mar 2020, 9:56 AM
Haider Ali
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 ☝
27th Mar 2020, 10:36 AM
Ipang
0
declare pname and pteam as array type like pname[5] and pteam[5]
27th Mar 2020, 3:10 PM
satya sri
satya sri - avatar
0
Your pname and pteam are not arrays
27th Mar 2020, 6:28 PM
emmanuel
emmanuel - avatar
0
You have to use String instead of Char
29th Mar 2020, 5:44 AM
Mathurantha Kanthakumar
Mathurantha Kanthakumar - avatar
0
#include<iostream.h> Using namespace std; class player { Private: char pname[20];. char pteam[20];. int avg;
29th Mar 2020, 5:48 AM
T. Siva Kiran
T. Siva Kiran - avatar
0
Here access specifier private: Is missed
29th Mar 2020, 5:49 AM
T. Siva Kiran
T. Siva Kiran - avatar