Hello. (This is my first post so bear with me) I'm trying to make a program with slot machines and I'm having problems. I want to have the user pick an amount of quarters between 1 and 1000. Also, I input different numbers of quarters and the amount the slot machines have been played and it always displays the same number for the amount of times she played. All help is appreciated and thank you for your time.
The original problem statement is:
Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 9 quarters every 10th time it is played.
Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.
Your program should output the number of times Martha plays until she goes broke.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main ()
{
int int_jar;
int int_playcounter;
int int_turn1;
int int_turn2;
int int_turn3;
cout << "How many quarters are in Martha's jar?" << endl; // Takes the number of quarters in Martha's jar before she starts to play
cin >> int_jar; // User's choice of number of quarters
cout << "How many times has the first machine been played since last payout?" << endl; // number of times slot machine one has been played since last payout
cin >> int_turn1; // User's choice of number of times played since last payout
cout << "How many times has the second machine been played since last payout?" << endl; // number of times slot machine two has been played since last payout
cin >> int_turn2; // User's choice of number of times played since last payout
cout << "How many times has the third machine been played since last payout?" << endl; // number of times slot machine three has been played since last payout
cin >> int_turn3; // User's choice of number of times played since last payout
while (int_jar=1>1000)
{
int_turn1 ++;
int_playcounter ++;
if (int_turn1==35) // Gets payed every 35 times
{
int_jar+=30; // Pays 30 quarters
}
int_turn2 ++;
int_playcounter ++;
if (int_turn2==100) // Gets payed every 100 times
{
int_jar+=60; // Pays 60 quarters
}
int_turn3 ++;
int_playcounter ++;
if (int_turn3==10) // Gets payed every 10 times
{
int_jar+=9; // Pays 9 quarters
}
}
cout << "Martha plays " << int_playcounter << " times before going broke. "; // Displays how many times Martha played
system("PAUSE");
return 0;
}
line 22: (int_jar=1>1000) That expression makes no sense. It tests if 1 is > 1000, the assigns the result (false) to int_jar.
line 25,30,35: if is not capitalized.
line 40: system is not capitalized.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I was typing this all on my phone but in the original code, while, if, etc...is not capitalized. Spell check just made it that way. Though, I went back and made the changes you suggested. I hope this has made it easier for you and others to read.
I was desperate to fix and finish this code because I just don't know what's wrong with it and others I've asked can't seem to figure it out either. It's also not on my own computer so I had to take a picture of it and type it on my phone.
Well if you take what I have already, the code takes the number of quarters the user has chosen and sets that as the starting amount that is in the jar. I want that number to be between 1 and 1000 and for the program to say "invalid amount", or something along those lines, if the amount is below 1 or above 1000.
It then asks the amount of times slot machine 1, slot machine 2, and slot machine 3 have been played since last payout. I enter a number of different sets of three numbers for the three machines and it gives me the same number each time, which I know the number is wrong.
There's a chart that was written up with the program. I'll add it to see if this helps to understand my problems better.
#of coins in the jar: 50
Times machine #1 has been played since last payout: 5
Times machine #2 has been played since last payout: 50
Times machine #3 has been played since last payout: 5
Total #of times played until she is broke: 68
So as one example: Martha has 50 quarters in her jar. Machine 1 has already been played 5 times, machine 2 has been played 50 times and machine 3 has been played 5 times. She played 68 times before she became broke.