Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help please

hulio_hulio_ Member Posts: 29
I'm having a problem with a roulette game I'm making for school in C++. Everything seems to be working fine except that it doesn't give you the money that you win. Here's the code.
[hr]
[code]
#include
#include

#include "stdlib.h"
#include "time.h"
using namespace std;

int bets_made,bet_num[50], betmoney[50];
short roulette_choice,spinval;
double num_bets;
long cash;



int main()
{
cash = 500;
main:
short bet = 0;

while(!bet)
{
menumain:cout << "


***Menu***
";
cout << "(1):Place a bet
";
cout << "(2):Check your cash
";
cout << "(3):Mortgage your house
";
cout << "(4):Quit roulette
";
cout << "(5):Retire
";
cout << "Please enter your choice: ";
cin >> roulette_choice;

switch(roulette_choice)
{

case 1: cout << "


How many bets will you place?";
cin >> num_bets;
num_bets = num_bets - 1;
bets_made = -1;

while(bets_made < num_bets)
{
bets_made++;
beginning:
cout << "
What number will you place a bet on(0-36)? ";
cin >> bet_num[bets_made];

if(36 < bet_num[bets_made] || 0 > bet_num[bets_made])
{
goto beginning;
}

cout << "How much will you bet on number " << bet_num[bets_made] << "?";
cin >> betmoney[bets_made];

}
bet = 1;

break;

case 2: cout << "

You have $" << cash << " at this time.";
break;

case 3: cout << "

I think you need to go cool it for a while.";
return 0;

case 4: cout << "

Returning to the main menu now.";
return 0;


case 5: return 0;

default: cout << "


Stay away from the bar for a while would ya?";
goto menumain;
break;
}
}

spinval = rand() %37;
cout << "


The winning number is "<< spinval << "!";

int betcheck = -1;

while(betcheck < num_bets)
{
betcheck ++;
if(bet_num[betcheck] - spinval == 0)
{
cout << "


You won with the number " << bet_num[betcheck] << "!";
cash = cash + (betmoney[betcheck] * (37.00/num_bets)) ;
cout << "
You made $" << betmoney[betcheck] * (37.00/(num_bets+1)) << " off of this game!";
goto main;
}

}
[/code]
[hr]

Thanks ahead of time for any help.

Comments

  • rohitprohitp Member Posts: 6
    hi, this program works in my comp. try in yurs.
    -Rohit.




    #include
    #include
    #include
    #include "stdlib.h"
    #include "time.h"

    int bets_made,bet_num[50], betmoney[50];
    short int roulette_choice,spinval;
    double num_bets;
    long int cash;

    int main()
    {
    cash = 500;
    main:
    short bet = 0;
    while(!bet)
    {
    menumain:cout << "


    ***Menu***
    ";
    cout << "(1):Place a bet
    ";
    cout << "(2):Check your cash
    ";
    cout << "(3):Mortgage your house
    ";
    cout << "(4):Quit roulette
    ";
    cout << "(5):Retire
    ";
    cout << "Please enter your choice: ";
    cin >> roulette_choice;
    switch(roulette_choice)
    {
    case 1: cout << "


    How many bets will you place?";
    cin >> num_bets;
    num_bets = num_bets - 1;
    bets_made = -1;
    while(bets_made < num_bets)
    {
    bets_made++;
    beginning:
    cout << "
    What number will you place a bet on(0-36)? ";
    cin >> bet_num[bets_made];
    if(36 < bet_num[bets_made] || 0 > bet_num[bets_made])
    goto beginning;
    cout << "How much will you bet on number " << bet_num[bets_made] << "?";
    cin >> betmoney[bets_made];
    }
    bet = 1;
    break;

    case 2: cout << "

    You have $" << cash << " at this time.";
    break;

    case 3: cout << "

    I think you need to go cool it for a while.";
    return 0;

    case 4: cout << "

    Returning to the main menu now.";
    return 0;

    case 5: return 0;

    default: cout << "


    Stay away from the bar for a while would ya?";
    goto menumain;

    }
    }
    spinval = rand() %37;
    cout << "


    The winning number is "<< spinval << "!";
    int betcheck = -1;
    while(betcheck < num_bets)
    {
    betcheck ++;
    if(bet_num[betcheck] - spinval == 0)
    {
    cout << "


    You won with the number " << bet_num[betcheck] << "!";
    cash = cash + (betmoney[betcheck] * (37.00/num_bets)) ;
    cout << "
    You made $" << betmoney[betcheck] * (37.00/(num_bets+1)) << " off of this game!";
    goto main;
    }
    }
    getch();
    }




  • hulio_hulio_ Member Posts: 29
    Thanks for the help Rohitp, but that isn't working either. If you check your cash after winning (that would be numbers 4, 4, 7, 8 in that order. I already memorized it for debugging), it always equals 0. I'm working out of Microsoft Visual C++ 6.0 if that has any impact on it. Also, this roulette game is going to be changed into a function named Roulette(), and stuck into another program. I'm not sure if any of this information will help, but I'll feel better sticking it on here.
    Thanks for taking the time to help me anyways rohitp!
Sign In or Register to comment.