find the highest scorer and name?
Can somebody help me find the highest scorer and the name of the person that scored the highest? This is what I have so far...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
using namespace std;
const int PLAYER_SIZE=40;
void getData(soccerData *);
struct soccerData
{
int numberPlayer;
int pointsScored;
char namePlayer[PLAYER_SIZE];
int highestScore;
int nameHighest;
};
int main()
{
const int NUM_PLAYERS=12;
soccerData players[NUM_PLAYERS];
int index;
//Ask info
cout<< "Enter names, numbers, and points. "<<endl;
for (index=0; index<NUM_PLAYERS; index++)
{
//get name
cout<< "Players name "<<(index+1);
cout<<": ";
cin>> players[index].namePlayer;
//get points
cout<< "Points scored "<<(index+1);
cout<<": ";
cin>>players[index].pointsScored;
//get numbers
cout<<"Player's number "<<(index+1);
cout<<": ";
cin>>players[index].numberPlayer;
}
//Display
for(index=0; index<1; index++)
{
double total;
total=players[index].pointsScored;
cout<<"Total points ";
cout<<": "<<total*12<<endl;
}
return 0;
}
void getData(soccerData*)
{
highestScore = pointsScored[0];
for (int count =1; count < NUM_PLAYERS;count++)
{
if (pointsScored[count]> highestScore)
highestScore = pointsScored[count];
nameHighest = count;
}
cout<<" The highest scorer is "<< PLAYER_SIZE[nameHighest] << " : "<<highestScore<<endl;
}
|
Somebody fix it for me?
whats the point of using this for loop if you're only iterating once? you might just get rid of the for loop dood.
1 2 3 4 5 6
|
for(index = 0; index < 1; index++)
{
double total;
total= players[index].pointsScored;
cout<< "Total points " << ": " <<total * 12 << endl;
}
|
and when I compile this, it says soccerData was not declared in the scope. I'll let you fix that...
that's the problem, I changed it but I messed it up...please help
this is the new program, but now i cant figure out the total:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
using namespace std;
const int PLAYER_SIZE=40;
const int NUM_PLAYERS=4;
struct soccerData;
//void getData(soccerData *);
struct soccerData
{
int numberPlayer;
int pointsScored;
char namePlayer[PLAYER_SIZE];
};
int main(){
soccerData players[NUM_PLAYERS];
soccerData winner;
double highestGoals = -1;
//Ask info
cout<< "Enter names, numbers, and points. "<<endl<<endl;
for (int index=0; index<NUM_PLAYERS; index++){
//get name
cout<< "Players name "<<(index+1);
cout<<": ";
cin>> players[index].namePlayer;
//get points
cout<< "Points scored "<<(index+1);
cout<<": ";
cin>>players[index].pointsScored;
//get numbers
cout<<"Player's number "<<(index+1);
cout<<": ";
cin>>players[index].numberPlayer;
cout<<endl<<endl;
}
//Display
for(int index = 0; index < NUM_PLAYERS; index++){
if(players[index].pointsScored > highestGoals){
highestGoals = players[index].pointsScored;
winner = players[index];
}
}
cout<<"Winner is "<<winner.namePlayer<<" "<<"and he scored "<<highestGoals<<" goals "<<endl;
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.