I'm writing a slot machine program where you are supposed to start with 1000 quarters but for some reason its counting down from some random number higher than the quarters=1000; I declared. The program is supposed to run till you run out of quarters. Can someone shed light on my problem?
The first machine pays 25 quarters every 33th time it is played;
the second machine pays 75 quarters every 99th time it is played;
the third pays 7 quarters every 9th time it is played.
Code:
#include <stdio.h>
int slot1(int, int );
int slot2(int, int );
double convertQuarters (int);
void main(){
int timesPlayed = 0;
int timesPlayed2 = 0;
int input3;
double x;
int quarters=1000;
while(quarters>0) {
//quarters--;
quarters+= slot1(timesPlayed++, --quarters );
quarters+= slot2(timesPlayed2++, --quarters );
quarters+= slot3(timesPlayed2++, --quarters );
//timesPlayed++;
/* printf ("\nSlot Machine Two\n");
printf("Press 1 to Insert Quarter\n");
scanf ("%d", &input2);
printf("Sorry You Lose\n");
// winnings = .25*75;
//quarters=quarterTotal-99;
// total=.25*quarterTotal;
if (input1==99){
printf ("You've Won 75 Quarters on machine 1!\nYou've won $%.2lf\n", winnings);
printf ("You Have %.2lf quarters left which equals $%.2lf\n\n", quarters, total);
}
printf ("\nSlot Machine Three");
printf("\nPress 1 to Insert Quarter\n");
scanf ("%d", &input3);
printf("Sorry You Lose\n");
quarters=quarterTotal-9;
total=.25*quarterTotal;
if (input1==9){
printf ("You've Won 7 Quarters on machine 1!\nYou've won $%.2lf\n", winnings);
printf ("You Have %.2lf quarters left which equals $%.2lf", quarters, total);
system ("pause");
}
*/
printf ("You have %d quarters left\n", quarters);
} //End While Loop
system ("pause");
}
int slot1(int timesPlayed, int quarters)
{
int winnings=0;
printf ("Slot Machine One\n");
if (timesPlayed%33==0){
printf("You won on slot machine 1\n");
quarters+=25;
printf ("You have %d quarters left\n", quarters);
winnings= 25;
}
return winnings;
}
int slot2(int timesPlayed, int quarters)
{
int winnings=0;
printf ("Slot Machine Two\n");
if (timesPlayed%99==0){
printf("You won on slot machine 2\n");
quarters+=75;
printf ("You have %d quarters left\n\n", quarters);
printf ("You have %.2lf quarters left\n", convertQuarters(quarters));
winnings= 75;
}
return winnings;
}
int slot3(int timesPlayed, int quarters)
{
int winnings=0;
printf ("Slot Machine Three\n");
if (timesPlayed%9==0){
printf("You won on slot machine 3\n");
quarters+=25;
printf ("You have %d quarters left\n\n", quarters);
printf ("You have %.2lf quarters left\n", convertQuarters(quarters));
winnings= 25;
}
return winnings;
}
double convertQuarters (int quarters)
{
double result;
result=quarters*.25;
return result;
}