im doing a code that has to include a nested loop...,how would i do that..
example.
a bowling team consists of five players.Each player bowls three games. use a nested loop to enter each player's individual scores and then computes and displays the average score for each bowler.
p.s this isnt my homework this was just a question i found and i wanted to see how it would work
A nested 'for' loop, for example, is just a for loop inside the body of another for loop. IE:
1 2 3 4 5 6 7 8 9 10
...
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 3; j++ )
{
//inner body
cout << i << " " << j << "\n"; //print values of both variables
}
}
...
int playerScore = newint[totalPlayers];
int playerGames = newint[totalPlayers];
for (int player = 1; player <= totalPlayers; player++)
{
int tempScore;
for (int game = 1; game <= 3; game++)
{
cout << "What score did player " << player << " score in game " << game << "?:\t";
cin >> tempScore;
playerScore[player - 1] += tempScore;
playerGames[player - 1]++;
cout << "At this point, player " << player << has a total of << playerScore[player - 1] << " and an average score of " << ( playerScore[player - 1] / playerGames[player - 1]) << ".\n";
}
}