0

Hello everyone for c++ structure basics

I was wondering if there is anyone that can help me out on this. I'm starting to learn structures and I want to know if this is correct . Its pretty basic but for some reason when I run with a test case it wont compile. #include <iostream> #include <string> #include <iomanip> using namespace std; struct Player {    string name;    int number;    string team;    string position;    double battingAverage; }; Player readPlayer() {  cout << "Enter a player name \n";  cin >> name;  cout << "Enter their number \n";  cin >> number;   getline(256, '\n');  cout << "Enter their team name \n";  cin >> team;  cout << "Enter their position \n";  cin >> position;  cout << "Enter their batting average \n";  cin >> battingAverage;   getline(256, '\n');       } void printPlayer(const Player& player) {   cout << "Player : " << name << endl;   cout << "Number : " << number << endl;   cout << "Team : " << team << endl;   cout << "Position : " << position << endl;   cout << "battingAverage : " << battingAverage << endl; }

30th Nov 2020, 7:50 PM
boba
boba - avatar
1 Answer
+ 1
#include <iostream> using namespace std; struct Player { string name; int number; string team; string position; double battingAverage; }; void printPlayer(const Player& player) { cout << "Player : " << player.name << endl; cout << "Number : " << player.number << endl; cout << "Team : " << player.team << endl; cout << "Position : " << player.position << endl; cout << "battingAverage : " << player.battingAverage << endl; } int main(){ Player readPlayer; cout << "Enter a player name \n"; cin >> readPlayer.name; cout << "Enter their number \n"; cin >> readPlayer.number; cout << "Enter their team name \n"; cin >> readPlayer.team; cout << "Enter their position \n"; cin >> readPlayer.position; cout << "Enter their batting average \n"; cin >> readPlayer.battingAverage; printPlayer(readPlayer); return 0; }
30th Nov 2020, 8:02 PM
rodwynnejones
rodwynnejones - avatar