Bowling Program

Hello, I'm stuck with this program I'm trying to make. This is what I'm supposed to do:

create a program that will track the results of each throw, 2 per frames 1-9 and 2-3 in frame 10.

Here 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
#include <iomanip>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <ctime>
#include <windows.h>
using namespace std;
int main()
{
	srand(time(NULL));
	
		int finalScore = 0;
		char throws[21];
		int rolls [21];
		int scores [10];
		
		int rollA;
		int rollB;
		int rollC;
		int y=0;
		int frame;
		
		for(int x = 0; x < 21; x++)
			throws[x] = ' ';
		
		for(int x = 1; x <= 9; x++)
		{
			rollA = rand() % 11;
	
		}
			
}


I can only use those headers shown in the program above.

The output should be a frame as shown from this website link: https://www.bowl.com/Welcome/Welcome_Home/Keeping_Score/

Any help would be greatly appreciated. Thank you!
Last edited on
Hello axi,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Your program in code tags with comments:
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
#include <iomanip>
#include <iostream>
#include <string>
#include <stdlib.h>  // <--- Should use <cstdlib>.
#include <ctime>
#include <windows.h>  // <--- And this is for?

using namespace std;  // <--- Best not to use.

int main()
{
    //srand(time(NULL));
    srand(static_cast<unsigned int>(time(nullptr)));

    int finalScore{};  // <--- ALWAYS initialize all your variables.
    char throws[21]{};
    int rolls[21]{};
    int scores[10]{};

    int rollA{};
    int rollB{};
    int rollC{};
    int y{};
    int frame{};

    for (int idx = 0; idx < 21; idx++)  // Unnecessary if you initialize your variale, unless you want each element to be a space.
        throws[idx] = ' ';

    for (int idx = 1; idx <= 9; idx++)
    {
        rollA = rand() % 11;
    }

    return 0;  // <--- Not required, but makes a good break point for testing.
}

At this point including "windows.h" has no benefit to the program.

In C++ there are several C header files that have a C++ version that start with "c". These should be what you use. See the reference section here for a list of these.

I do not see any use for the first for loop. As long as you initialize the variable when you define it it will be filled with (0)zeros or (\0)s. Later on you will be changing these values in the array.

The 2nd for loop is for what? You are looping 9 times, but "rollA" will only contain the value of the last loop. Also you are getting a random number for this value when you should be asking the user to enter a value for the frame.

Looking at your link this explains how to keep score. Your program needs to be dealing with the frames and rolls the same way.

I would suggest mentioning what IDE and compiler you are using along with what you have studied so far. This will help cut down on suggestions that are beyond what you have learned. Even if those suggestions are a better way of writing the program.

Andy
Topic archived. No new replies allowed.