VS C++ program issues, I have 4 errors that are preventing me from creating the
ID: 639944 • Letter: V
Question
VS C++ program issues, I have 4 errors that are preventing me from creating the output. Please help me fix these errors, they all pertain to line 50.
C2057: expected constant expression
C2466: cannot allocate an array of constant size 0
C2133: 'p': unknown size
IntelliSense: expression must have constant value
Below is my code
----------------------------------------------------------------------------------
#include
#include
using namespace std;
struct Player
{
char name[30];
int number;
int points;
};
void getPlayerInfo(Player &p) //here we receiving using call by reference since we have to store the info of player which is declared in main
{
cout << "Player name : ";
cin >> p.name;
cout << "Player's number : ";
cin >> p.number;
cout << "Points scored : ";
cin >> p.points;
}
void showInfo(Player p)
{
cout << p.name << setw(25); //it will print name in 25 width means if name is smaller than 25 char blank spaces are given next so that total occupy 25 char
cout << p.number << setw(20);
cout << p.points << " ";
}
int getTotalPoints(Player p[], int number_of_player)
{
int i, total_points = 0;
for (i = 0; i total_points = total_points + p[i].points; //calculation total. on each iteration we are adding ith player's point to total
return total_points; // returning total point
}
void showHighest(Player p[], int number_of_player)
{
int i, maxpoint = 0, maxpointplayer_index; //initially we set maxpoint=0
for (i = 0; i {
if (maxpoint
{
maxpoint = p[i].points; // if maxpoint is less then any player's point than that player's point choosen as maxpoint
maxpointplayer_index = i; // and maxpointplayer_index gives the player which have highest point
}
}
cout << " The player who scored the most points is : " << p[maxpointplayer_index].name;
}
int main()
{
int i, number_of_player = 12;
Player p[number_of_player]; //declaring array of players
for (i = 0; i {
cout << " PLAYER #" << i + 1 << " ";
cout << "-------- ";
getPlayerInfo(p[i]); //getting info of each player
}
cout << " NAME NUMBER POINTS SCORED ";
for (i = 0; i {
showInfo(p[i]); //showing information of each player
}
cout << " TOTAL POINTS : " << getTotalPoints(p, number_of_player); //call to function for getting total points by passing arraybase,number of players
showHighest(p, number_of_player); //call to function which determines highest point player
}
Explanation / Answer
at player p[] in functions i think so
array declaration wrong....improper for loops
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.