Using 1D array for bowling scores

Hey y'all-

I'm trying to write code that will display scores of a bowling game with both the score per frame and a running total score of the game, like this:


Frame     Score     Game
  1         20        20
  2         17        37
  3          9        46
  4         29        75
  5         19        94
  6          9       103
  7         19       122
  8         20       142
  9         20       162
  10        19       181


I've got an array set up for the frame scores and to accumulate for the running total, but I'm having a problem with something quite simple- outputting the frame numbers and score. I'm trying to find an eloquent way to do it within the for loop, but I'm lost..

Here's what I have thus 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
#include <iostream>
#include <iomanip>
using namespace std;

int main(void)
{
   
   const int SIZE = 10;


   void  displayScores(const int scores[], const int SIZE);


   int scores[SIZE] = {20, 17, 9, 29, 19, 9, 19, 20, 20, 19};


   cout << "*** start of 276Arrays_01.cpp program ***" << endl;
   cout << endl;

   displayScores(scores, SIZE);

   cout << endl;
   cout << "*** end of 276Arrays_01.cpp program ***" << endl << endl;
   cin.get();

   return 0;

}

void displayScores(const int scores[], const int SIZE)
{
	
	// declare variables
	int frame = 0;
	int game = 0;

	// column headings
	cout << setw(5)  << "Frame";
	cout << setw(5) << " ";
	cout << setw(5)  << "Score";
	cout << setw(5)  << " ";
	cout << setw(4)  << "Game\n";
	
	//Accumulate running total score & display scores
	for (int i = 0; i <= SIZE; i++)
	{
		game += scores[i];

		// column data
		cout << setw(3) << right << "1";
		cout << setw(11) << right << scores[0];
		cout << setw(10) << right << game << endl;
	}
		
		
}

Where is the game array?
What do you mean by "eloquent"?
game is not an array, it's just a placeholder for the accumulating scores.. Do i need to make a game array so it could actually store each running total number?
by eloquent I mean I'm trying to keep everything contained to just one for loop if possible.. If not, I'm not sure how the accumulator would work
No, you don't need a game array. I've misunderstood your question.
I think that if you change score[0] in score[i] in line 51, you'll have a better result :)
Ciao.
Last edited on
Line 45 shouldn't be using <=.

Line 51 shouldn't be using scores[0]
Topic archived. No new replies allowed.