Soldato
- Joined
- 4 Mar 2006
- Posts
- 3,712
- Location
- Wales
Hi all, I'm working on the below piece of code, and am having a lot of trouble passing an array through to another function. I've highlighted in red where I called the function, but I was wondering if you could take a look and perhaps point out why it won't let me pass it through 
First, sorry for the lack of comments in the code, so I'll include my mission statement so you know what's what.

First, sorry for the lack of comments in the code, so I'll include my mission statement so you know what's what.
Mission Statement said:Using the struct mechanism, create a structure with the name ATopPlayer. The structure should have two members: PlayerName and PlayerScore. Set up an array called HSL (short for High Score List) of four of these structure elements. The array should initially contain no names and no scores.
Write the code that allows the HSL table to be updated from the keyboard. The code should be set up so that it terminates when a score of -1 is entered.
The HSL should be ordered so that the highest score is in position 0 and the next lowest at position 1 etc. Each time a player’s score is entered the program should work out whether it is high enough to be included in the HSL. If it is, then the player’s name should also be requested by the program and entered by the user.
Each time a new score is added to the HSL other elements might have to move. For example, say the first score entered was 42 then, as it is the highest score to date, this would be put into position 0. Now if the next score was 59, the value 42 and the name of the player that obtained the score would be moved from position 0 to position 1 while the value 59 and the name of the player that obtained the score would be put in position 0. Obviously as more scores get entered names and values that were originally stored in HSL might be removed from the table altogether.
After each score/name is entered an updated HSL should be displayed on the screen.
Broken Code said:#include "stdafx.h"
#include <string.h>
#include <iostream.h>
int CompareScores(float, float) ;
void TableOrder (struct, char, float, const) ;
struct ATopPlayer {
char PlayerName[50] ;
float PlayerScore ;
} ;
int main(int argc, char* argv[])
{
char Name[50] = "" ;
float Score = 0 ;
ATopPlayer HighScore1, HighScore2, HighScore3, HighScore4 ;
HighScore1.PlayerScore = 0 ;
HighScore2.PlayerScore = 0 ;
HighScore3.PlayerScore = 0 ;
HighScore4.PlayerScore = 0 ;
ATopPlayer HSL [4] ;
HSL[0]=HighScore1 ; HSL[1]=HighScore2 ; HSL[2]=HighScore3 ; HSL[3]=HighScore4 ;
const ArrayPlaces = 4 ;
while (Score != -1)
{
cout << "Please input your name and score. Input a score of -1 to terminate the program.\n" ;
cout << "Player Name : " ;
cin >> Name ;
cout << "Score : " ;
cout << Score ;
int ScoreCompare = CompareScores (Score, HighScore4.PlayerScore) ;
if (ScoreCompare == 1)
TableOrder (HSL, Name, Score, ArrayPlaces) ;
else
cout << "You score wasn't good enough! Try again." ;
cout << "HIGH SCORES\n-----------\n"
<< "First Place : "
<< HighScore1.PlayerName
<< " with a score of "
<< HighScore1.PlayerScore << endl
<< "Second Place : "
<< HighScore2.PlayerName
<< " with a score of "
<< HighScore2.PlayerScore << endl
<< "Third Place : "
<< HighScore3.PlayerName
<< " with a score of "
<< HighScore3.PlayerScore << endl
<< "Fourth Place : "
<< HighScore4.PlayerName
<< " with a score of "
<< HighScore4.PlayerScore << endl ;
}
return 0;
}
int CompareScores (float PlayerScore, float LowestScore) ;
{
int TableEntry = 0 ;
if (Playerscore > LowestScore)
Table Entry = 1 ;
return TableEntry ;
}
void TableOrder (HSL[], char NewName[50], float NewScore, const ArrayPlaces)
{
NameHolder = "", NameHolder2 = "" ;
float ScoreHolder = 0, ScoreHolder2 = 0 ;
int i = 0 ;
ScoreHolder2 = NewScore ; NameHolder2 = NameHolder ;
for (int counter=0 ; counter<4 ; counter++)
{
if (NewScore > ATopPlayer[counter].PlayerScore)
{
int PlayerPosition = counter ;
break ;
}
}
while (PlayerPosition > 5)
{
NameHolder = ATopPlayer[PlayerPosition].PlayerName ;
ScoreHolder = ATopPlayer[PlayerPosition].PlayerScore ;
ATopPlayer[PlayerPosition].PlayerName = NameHolder2 ;
ATopPlayer[PlayerPosition].PlayerScore = ScoreHolder2 ;
NameHolder2 = NameHolder ;
ScoreHolder2 = ScoreHolder ;
PlayerPosition + 1 ;
}
}