i have written a program to play a game of roulette with out red or black
here is the code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
//doubles for money
double startmoney;
double account;
double moneybet;
double winning;
//intergers for betting
int oddeven;
int number;
int x;
int exit;
int bet;
printf("\nEnter the ammount of money you are starting with: $");
//enter money you want to start with
scanf("%lf", &startmoney);
account=startmoney;
//loop to keep the game going while you have money
while(account>0)
{
srand(time(0));
printf("\nEnter your bet: $");
scanf("%lf", &moneybet);
//asking how much the player would like to bet
printf("\nSelect: 1 to bet on odd\n 2 to bet on even\n 3 to bet on a particular number\n.");
//Asking the player which kind of bet they would like to make
scanf("%lf", bet);
//loop for the oddeven bet
if(bet==1)
{
x=rand() % 38;
printf("The ball has landed on %i\n", x);
oddeven=x%2;
//loop for if you lose the bet of a green slot
if(x==37||x==0)
{
winning=0;
account= account-moneybet;
printf("The ball has landed on a green slot.");
printf("\nYou lose the bet.");
printf("\nYou now have $%.2lf:", account);
}
//loop for if you win on a odd slot
if(oddeven!=0&&x!=0&&x!=37)
{
winning=moneybet;
account=winning+account;
printf("\nThe ball has landed on odd.");
printf("\nYour total winnings are $%.2lf.", winning);
printf("\nYour current acount is $%.2lf", account);
}
//loop for if you loose on a odd slot
else
{
winning=0;
account=account-moneybet;
printf("\nSorry, You Lose $%.2lf");
printf("\nYour current account is $%.2lf",account);
}
}
//loop for if you choose a even slot
if(bet==2)
{
x=rand()%38;
printf("The ball has landed on %i", x);
oddeven=x%2;
//loop for if you lose your bet by landing on a green slot
if(x==37||x==0)
{
winning=0;
account=account-moneybet;
printf("\nYou have landed on a green slot.");
printf("\nYou lose your bet.");
printf("\nYour current account is $%.2lf",account);
}
else
if(oddeven==0&&x!=0&&x!=37)
{
winning=moneybet;
account=winning+account;
printf("\nYou have won your bet.");
printf("\nYour winnings are $%.2lf", winning);
printf("\nYour account balance is $%.2lf", account);
}
else
{
winning=account-moneybet;
account=account-winning;
printf("\nSorry you lose.");
printf("\nYour account balance is $%.2lf",account);
}
}
//loop for if you are choosing a exact number to bet on
if(bet==3)
{
printf("\nEnter the number you would like to bet on (1 - 36 only): ");
scanf("%i",number);
x=rand()%38;
printf("\nThe ball landed on %i",x);
//if you loose by landing on 37 or a 0
if(x==37||x==0)
{
winning=0;
account=account-moneybet;
printf("\nYou have landed on a green slot");
printf("\nYou lose your bet.");
printf("\nYour account balance is $%.2lf",account);
}
//loop for if you win on your number
if(x==number&&x!=0&&x!=37)
{
winning=account+moneybet;
printf("\nYou have won your bet.");
printf("\nYour winnings are $%.2lf",winning);
printf("\nYour account balance is $%.2lf", account);
}
//loop for if you lose on your number
else
{
account=account-moneybet;
printf("\nSorry you lose.");
printf("\nYour account balance is $%.2lf", account);
}
}
//prompt to exit
printf("Enter 0 to quit, 1 to continue playing: ");
scanf("%i",&exit);
if(exit=0)
{
return 0;
}
}
return 0;
}
i am using cygwin bashshell to make/execute the program and when i am prompted to choose what kind of bet i want to make i get Error while dumping state <probably corrupted stack>