Bowling Program

Hello, I'm writing a program to keep score of a game of bowling. Whenever I run the program, it comes up with the correct starting point, but whenever i type in the first number and click enter, the program stops running and it gives a return value of something similar to 3221225477. Here is my code. I think the problem might be that I'm not using pointers..? but I could be way off..I'm new to programming.

P.S. sorry about the long code but it's pretty spread out

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
#include <stdio.h>

int main()
{
	int frame[10][3] = {{0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0,0}};
	int frameOutcome[10], frameTotal[10], currentFrame = 0, totalScore = 0;
	
	printf("\t\t\tWelcome to Bowling!\n\t\t\t-------------------");
	
	do
	{
		printf("\n\t\t\tFrame %d\n\t\t\t\tBall 1: ", currentFrame + 1);
		scanf("%d", frame[currentFrame][0]);
		
		if (frame[currentFrame][0] < 0 || frame[currentFrame][0] > 10)
			printf("Invalid Input");
		
		if (frame[currentFrame][0] = 10)
		{
			printf("Strike!");
			frameOutcome[currentFrame] = 2;
			currentFrame++;
		}
		else
		{
			printf("\n\t\t\tFrame %d\n\t\t\t\tBall 2: ", currentFrame + 1);
			scanf("%d", frame[currentFrame][1]);
			
			if (frame[currentFrame][1] < 0 || frame[currentFrame][0] + frame[currentFrame][1] > 10)
				printf("Invalid Input");
			
			if (frame[currentFrame][0] + frame[currentFrame][1] == 10)
			{
				printf("Spare!");
				frameOutcome[currentFrame] = 1;
				currentFrame++;
			}
			else
			{
				printf("The total for frame %d is: %d", currentFrame + 1, frame[currentFrame][1] + frame[currentFrame][1]);
				frameOutcome[currentFrame] = 0;
				currentFrame++;
			}
		}
	} while (currentFrame < 9);
	
	do
	{
		printf("\n\t\t\tFrame %d\n\t\t\t\tBall 1: ", currentFrame + 1);
		scanf("%d", frame[currentFrame][0]);
		
		if (frame[currentFrame][0] < 0 || frame[currentFrame][0] > 10)
			printf("Invalid Input");
		
		if (frame[currentFrame][0] == 10)
		{
			printf("Strike!");
			frameOutcome[currentFrame] = 2;
			
			printf("\n\t\t\tFrame %d\n\t\t\t\tBall 2: ", currentFrame + 1);
			scanf("%d", frame[currentFrame][1]);
			
			if (frame[currentFrame][1] < 0 || frame[currentFrame][1] > 10)
				printf("Invalid Input");
			
			printf("\n\t\t\tFrame %d\n\t\t\t\tBall 3: ", currentFrame + 1);
			scanf("%d", frame[currentFrame][2]);
			
			if (frame[currentFrame][2] < 0 || frame[currentFrame][1] + frame[currentFrame][2] > 10)
				printf("Invalid Input");
				
			currentFrame++;
		}
		else
		{
			printf("\n\t\t\tFrame %d\n\t\t\t\tBall 2: ", currentFrame + 1);
			scanf("%d", frame[currentFrame][1]);
			
			if (frame[currentFrame][1] < 0 || frame[currentFrame][0] + frame[currentFrame][1] > 10)
				printf("Invalid Input");
			
			if (frame[currentFrame][0] + frame[currentFrame][1] == 10)
			{
				printf("Spare!");
				frameOutcome[currentFrame] = 1;
				printf("\n\t\t\tFrame %d\n\t\t\t\tBall 3: ", currentFrame + 1);
				scanf("%d", frame[currentFrame][2]);
				
				if (frame[currentFrame][2] < 0 || frame[currentFrame][2] > 10)
					printf("Invalid Input");
				
				currentFrame++;
			}
		}
	} while (currentFrame < 10);
	
	for (currentFrame = 0; currentFrame < 8; currentFrame++)
	{
		switch (frameOutcome[currentFrame])
		{
			case 0: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1];
			break;
			case 1: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1] + frame[currentFrame + 1][0];
			break;
			case 2: 
			if(frameOutcome[currentFrame + 1] == 2)
				frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame + 1][0] + frame[currentFrame + 2][0];
			else
				frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame + 1][0] + frame[currentFrame + 1][1];
			break;
		}
	}
	
	for (currentFrame = 8; currentFrame < 9; currentFrame++)
	{
		switch(frameOutcome[currentFrame])
		{
			case 0: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1];
			break;
			case 1: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1] + frame[currentFrame + 1][0];
			break;
			case 2: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame + 1][0] + frame[currentFrame + 1][1];
			break;
		}
	}
	
	for (currentFrame = 9; currentFrame < 10; currentFrame++)
	{
		switch(frameOutcome[currentFrame])
		{
			case 0: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1];
			break;
			case 1: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1] + frame[currentFrame][2];
			break;
			case 2: frameTotal[currentFrame] = frame[currentFrame][0] + frame[currentFrame][1] + frame[currentFrame][2];
			break;
		}
	}
	
	for (currentFrame = 0; currentFrame < 10; currentFrame++)
	{
		totalScore = totalScore + frameTotal[currentFrame];
		
		printf("Frame %d total score: %d", currentFrame + 1, frameTotal[currentFrame]);
	}
	
	printf("Total score = %d", totalScore);
}
Last edited on
Hello,

Here are my 2 cents:
1. Your error on line 13 is in fact a pointer issue. scanf takes two arguments, first the format of the data being read and then the location at which the data should be stored (i.e. a pointer.) I would do something along the lines of this:
scanf("%d", &(frame[currentFrame][0]));
You repeated this error on lines: 27, 50, 61, 67, 77, and 87 as well.

2. You are missing an equal sign on line 18:
You have:
if (frame[currentFrame][0] = 10)
You should have:
if (frame[currentFrame][0] == 10)


Life lesson:
Always compile with the -Wall flag. It will warn you of improper usage of pointer and other interesting issues that aren't necessarily "errors" but they are definitely mistakes.

More about -Wall:
http://stackoverflow.com/questions/2408038/what-does-wall-in-g-wall-test-cpp-o-test-do
Last edited on
Topic archived. No new replies allowed.