I'm a little confused by your code, you seem to be making things harder than they need to be.
Is the supposed to be able to choose heads or tails before each toss of the coin? Or do they make the choice and then the coin gets flipped 10 times based on that choice? (that's what the current code would suggest).
A few things to point out here:
Not quite sure what's going on here. This seems like a pointless couple of lines because the value is being incremented then immediately decremented, leaving you with the same value as before those two lines run.
You do realise that this is going to run eleven times, right?
1 2
|
counter--;
save_balance = TOTAL - counter;
|
You're making your program much harder than it needs to be here. Every time you reference save_balance, you're adding TOTAL to it, plus some sort of operation with the counter. Once save_balance has been assigned TOTAL, it contains 50. You don't need to keep assigning TOTAL to it. Also, there's a much easier way to keep track of the total.
I would go for something along the lines of the following (I'm going to assume that heads or tails is only chosen once and the coin is tossed 10 times based on that choice, as per your current setup):
I originally wrote out a full code solution for this but thought it'd be better if I wrote some pseudo-code that you can figure out yourself. I've saved the solution in case you need to see it later.
1 2 3 4 5 6 7 8 9 10 11 12
|
Declare variables representing input, current cash and coin face
Set cash to 50
Get input from user
for (number of tosses)
{
generate a random number for coin face
if (user input is equal to coin face)
increment cash
else
decrement cash
}
Display end total (output cash)
|
As I've said, I've written a full solution but I'm not sure it'll be beneficial to you if I just go ahead and post the whole thing. See if you can get anything from the example above and if you're still stuck let me know and I'll help further.