Thread: Roulette program help

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Roulette program help

    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>

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    i cant be bothered quoting all the little bits but just check over your code and fix the scanf statements, you are missing the & operator several times and also you need to add %d (for integer) instead of %i or %lf in a couple of places too, and do some indentation
    Last edited by rogster001; 02-15-2010 at 02:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM