Okay, I'm been getting this error now with my program (Intro to C) and I can't figure out what I'm missing. The program works fine now, but it appears my logic is incorrect. Everything works except at the end of the program, when the money=0, the program is supposed to end. But mine asks for a number and a bet again and ends the program after that. I'm not sure how to fix this. Any help would be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
printf("Place your bet on a number between 0 and 36:\n");
int choice;
scanf("%d", &choice);
printf("Enter a bet in dollars $:\n");
double bet;
scanf("%lf", &bet);
double money;
money=bet;
while(money>0 && bet!=0 && bet<=money)
{
int spin;
srand(time(NULL));
spin=(rand()%37);
if(spin==choice)
{
printf("The result of the spin is %d.\n", spin);
money+=bet+bet*5;
printf("You now have $%.2f to gamble with.\n", money);
}
else if(spin%2==0 && choice%2==0 || spin%2!=0 && choice%2!=0 )
{
printf("The result of the spin is %d.\n", spin);
money+=bet+bet;
printf("You now have $%.2f to gamble with.\n", money);
}
else
{
printf("The result of the spin is %d.\n", spin);
money=money-bet;
printf("You now have $%.2f to gamble with.\n", money);
}
printf("Place your bet on a number between 0 and 36:\n");
scanf("%d", &choice);
printf("Enter a bet in dollars $:\n");
scanf("%lf", &bet);
}
printf("Thank you for playing. You leave the table with $%.2f.\n", money);
return 0;
}Last edited by Winston_Churchill (2008-10-02 18:54:35)