Help with adjusting score after iteration

closed account (N0M9z8AR)
I need help with this code, is there a way I can make it so after the do while loop runs once, and when it does again, it uses the score 15 again instead of the previously calculated score, so i can never get to 0 or 50. I don't know what to change in the score function to make this possible.

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

#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

int rollDice(int hi, int lo)
{

    return rand()%(hi-lo+1)+lo;
}

int score(int diceTotal)
{

    int Score = 15;

        if(diceTotal<10) {
            Score -= 3;
        }

        if(diceTotal>14) {
            Score += 2;
        }


        if(diceTotal==13) {
            Score -= 7;
        }

        if(diceTotal>16) {
            Score += 4;
        }


        return Score;
}

int main()
{

    srand(time(NULL));
    int dice1, dice2, dice3, dice4;



    char roll;
    int total;
    int TotalScore = 15, rollScore;
    cout<<"Total Score: "<<TotalScore<<"\n\n";



    do {


        dice1 = rollDice(6, 1);
        dice2 = rollDice(6, 1);
        dice3 = rollDice(6, 1);
        dice4 = rollDice(6, 1);

        total = dice1 + dice2 + dice3 + dice3;

        rollScore = score(total);

        cout<<dice1<<" "<<dice2<<" "<<dice3<<" "<<dice4<<" Total: "<<total<<" Score: "<<rollScore<<"\n\n";

        cout<<"Roll again? Y/N: ";
        cin>>roll;

        if(rollScore == 0 || rollScore == 50) {
            break;

        }


    }while(roll == 'Y');


    return 0;

}
Make your 'Scor'e variable static, then it will initialized only by the first call an then it remains its value between other function calls.
static int Score = 15;
Topic archived. No new replies allowed.