Need help with program

I'm trying to write a simple bowling program and cannot figure out how to give a char a value. For instance, user inputs x for strike and then 30 (for now) is calculated.

Also, is it possible to have a user input as if they are in a bowling alley?
Instead of input scores like this
score: 1
2
3
4
5

input scores like this:

score: 1 2 3 4 5 --- total.

If not then I have to rethink what I want to do with my program.

Thanks for the help.

Here's the code.
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
  #include <iostream>

using namespace std;

void frame(string name){
     char x = '30';  // gives enormous number
     int scoreBoard[3][10] = {{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}};
     cout << "Frame:\t\t";
     for (int i = 0; i < 10; ++i)
         cout << scoreBoard[0][i] << "   ";
         cout << endl;
         cout << name << ":";
     int scores[10], total = 0;
     for (int i = 0; i < 10; ++i){
         cin >> scores[i];
         total += scores[i];
     }
     cout << name << " scored a " << total;
}
int main()
{

    int scores[10], total = 0;
    string name;
    cout << "Enter a bowler name: ";
    getline(cin, name);
    frame(name);
    return 0;
}
Last edited on
I'm not sure what you're trying to do (not a bowler myself), but you use double quotes for a string of characters and single quotes for a single character, ie char x = 'a'; If you want to give a character a short integer value you just say char x = 30; (no quotes).

You could also have the program spit out the results horizontally each time, ie

1
12
123

etc.

Or if you want the score per bowl and the total you could do

1
1

14
12

149
123

Or whatever.
Hi,

Thanks for the help with the output. I already spent too much time on trying to figure it out and didn't want to spend anymore.

For some reason I can't the x char to give a value. When I input x into my program I get "name scored a 962502269". I want the user to be able to input x as strike which is the best ball you can roll.
I think I see your problem. You are assigning the value 30 to the variable x, that will not make the program output an x if the number it gets is 30. To do that you need to do something like

if (score==30) cout>>"X"; else (other instructions)

The computer doesn't magically know what you want it to do, if you want it to do x if y is true you need to give it those instructions. A computer has no common sense, it cannot make connections on it's own.
Right, but there's no way for a user to input x and then the computer adds 30 to the total?

In bowling a strike which can be worth 30 points is denoted with an x.
Topic archived. No new replies allowed.