Gambling program

I feel like this is a really easy question, but I for some reason cannot figure out a code that will store the totalChips and then keep adding or subtracting to them. Every time it loops, it just starts over from 100 again.

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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <limits>
#include <cstdio>
using namespace std;




int totalChips = 100;

void PressEnterToContinue()
  {
  std::cout << "Press ENTER to EXIT... " << flush;
  std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' );
  }
int main()
{

    string roll;
    int die;
    int bet;

    cout << "Are You A Gambling Man?\n";
    cout << "You Have Recieved 100 Chips.\n";

while(totalChips > 0)

 {
    srand(time(0));
    int rNumber = 1+(rand()%6);

                                                    cout <<"Please Enter Bet\n";

                                                    cin >> bet;

                                                    cout << "Now Enter A Number From 1-6\n";

                                                    cin >> die;

                                                    cout << "You Are Ready! Please Type Roll.\n";
                                                    cin >> roll;
    if (roll == "Roll" or roll == "roll")

    {
        cout << "You rolled a " << rNumber << endl << endl;


    }

    if (rNumber == die)
    {

        cout << "Congradulations, you won " << bet << "!" << endl << endl;
        cout << "Your new amount is " << // this part right here  << endl << endl << endl;
    }

    else
    {
        cout << "Sorry! You lost " << bet << "." << endl << endl;
        cout << "Your New Amount is " << // this part also << endl << endl << endl;

    }


}



PressEnterToContinue();
getchar();


}



Also, if there are any suggestion to this code to make it any better I am all ears. Only my 4th day of programming so still learning!
closed account (Dy7SLyTq)
its probably because no where in your code is totalChips brought down by one at each iteration of the loop
i forgot to leave in what I was doing. I was doing totalChips + bet and then totalChips - bet. but that would just start from 100 again when it looped. I just need to know how to save it. I tried a couple different ways, but the output gave a ridiculous number each time
At the end of each comparison of die and rNumber change the value of totalChips, so that if he got the correct number, you increment it or otherwise--decrement it's value.
So, if(correct) increment else decrement
Oh I see what you mean DTS, but Matri made it a little more clear. Alright tyvm guys! That fixed it!
Topic archived. No new replies allowed.