What is an easy way to display the score after each inning? Instead of adding it all up at the end I want it to say Home Team is winning 8-2 after the first, second, third, etc inning. Stuck on this. I know how to display the added up value of all the elements AFTER the 9 innings are complete but how would I display it after every single inning.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int homeTeam[9];
int awayTeam[9];
int awayRuns;
int homeRuns;
int homeSum = 0;
int awaySum = 0;
for (homeRuns = 0; homeRuns < 9; homeRuns++)
for (awayRuns = 0; awayRuns < 9; awayRuns++)
{
cout << "Please enter the score after each inning for the Home Team: \n";
cin >> homeTeam[9];
cout << "Please enter the score after each inning for the Away Team: \n";
cin >> awayTeam[9];
homeSum = homeSum + homeTeam[9];
awaySum = awaySum + awayTeam[9];
cout << endl;
}
system("pause");
return 0;
}
If an array is declared like so: int arr[9];, then it has a size of 9, and its valid indices range from 0 to 8, inclusive. In other words, actually accessing arr[9] goes out of bounds; you can only access arr[0] to arr[8].