Repeating a program multiple times

Hey guys i have a small problem i have a program that is repeating using "do while" the program basically does some simple calculations lets say u enter a bet it calculates how much you won based on the bet...the problem is i want to tally all the money the person gets when the loop is executed multiple times how can i do that here is the basic structure of the program:

1
2
3
4
5
 do { 
            //program to be looped//


}while (statement);


Put the player_balance variable outside the loop.
1
2
3
4
5
6
7
8
int player_balance = 100;
do { 
            //program to be looped//

// adjust player_balance inside the loop based on amount won or lost.
}while (player_balance > 0);
cout << "Sorry, you're out of money" << endl;
exit (0);


BTW, what follows while is an expression or condition, not a statement.
thank you very much i can now calculate the overall money won...one more question i want to user to restart the program by choosing yes or closing no but also i want the program to only run 4 times...hers the code
1
2
3
4
 do {   
 // program to be looped

} while (c== 'y' || cnt<=4) 


when the c==y is at front it runs regardless if cnt is at 5...likewise cnt <=4 runs to four even if the user chooses to stop before cnt is 4...what am i doing wrong?
Last edited on
If one or the other is true.
c == 'y' OR cnt <= 4.

How do you change that so it only loops if both of those are true?
the and && operator i presume ...i feel so ashamed lol
Last edited on
Topic archived. No new replies allowed.