# making a program emulate roulette HELP!!

• 06-23-2010, 12:54 AM
manowar689
making a program emulate roulette HELP!!
ok heres the thing im trying to make a pogram to emulate a roulette table for practice but for some reason a certain question keeps looping when it shouldnt its this question "please input you bet now" now i have it set to loop till the bet is less then the stake therefore not betting with money you dont have the loop wont work tho it makes me enter more the the stake for some reason and the this if statement "if (num == Q2)" gets opened even if num being the number at random and Q2 being the users input arent the same any help would be appreicated :):):) ps i know there isnt a loop for if they lose but i havent got that far lol

Code:

``` //--------------------------------------------roulette table---------------- class roulette{         public static void main (String[] args){         int num;         int col;         int stake;         int Q2;         int bet;         int Q1; //------------------------------------------------------------------------- do{ stake = kdr.valgetint("\nplease enter the amount you would like to begin betting with min 1 max 1000:"); }while(stake<1 || stake>1000); //------------------------------------------------------------------------- //------------------------------------------------------------------------- do{ System.out.print ("\nplease enter what you would like to bet\n1:number\n2:colour"); Q1 = kdr.valgetint("\nplease input answer now: "); //------------------------------------------------------------------------- if(Q1 == 1) { do{ Q2 = kdr.valgetint("\nplease input you number now: "); }while(Q1>=36); do{ bet = kdr.valgetint("\nplease input you bet now: "); }while(bet<=stake); num = (int)(Math.random() * 36) + 1; if (num == Q2) {         if(num==2||num==4||num==6||num==8||num==10||num==11||num==13||num==15||num==17||num==20||num==22||num==24||num==26||num==28||num==29||num==31||num==33||num==35)         {         System.out.print ("\n"+num+" black");         System.out.print ("\nyou win!!!!");         stake = stake + (bet * 36);         System.out.print ("\nyour balance is "+stake+"");         }         else         {         System.out.print ("\n"+num+" red ");         System.out.print ("\nyou win!!!!");         stake = stake +(bet * 36);         System.out.print ("\nyour balance is "+stake+"");         } }```
• 06-23-2010, 01:54 AM
Norm
I'm not sure I understand your problem. Have you tried debugging your program by using println() to show the values of the variables like num.

Can you copy and paste the console from when you execute the program and add comments to it to show where the problem is?
• 06-23-2010, 02:34 AM
manowar689
i believe this is the problem so say the stake is 500 i want this to not proceed unless the bet is less then or equal to 500 and it wont proceed unless its greater then or equal to ?
thx btw
Code:

```do{ bet = kdr.valgetint("\nplease input you bet now: "); }while(bet<=stake);```
• 06-23-2010, 02:51 AM
Norm
Did you add a println() to the code to show the values of bet and stake?
How do you know what they are in the program?
• 06-23-2010, 09:48 PM
manowar689
this part sets the stake here kdr.valgetint simply just ensures that a valid interger is entered is all
Code:

```stake = kdr.valgetint("\nplease enter the amount you would like to begin betting with min 1 max 1000:"); }while(stake<1 || stake>1000);```
this part takes the bet and then i want it to ask it again until the bet is less then the stake the stake being money in the persons pocket if that makes sense
Code:

```do{ bet = kdr.valgetint("\nplease input you bet now: "); }while(bet<=stake);```
and wat difference would that make if i used println() ?? i am really new lol
• 06-23-2010, 10:05 PM
Norm
Quote:

what difference would that make if i used println()
The difference is that you would see what the values are and maybe understand what the problem is.
• 06-24-2010, 12:12 AM
manowar689
do you mean like a line like this

Code:

`println("+stake+")`
or just
Code:

`println()`
i assume this is just a print line command yes?
i use a keyboard.class which requires system.out.print so sorry if thats a noob question lol

thx again :D:D:D
• 06-24-2010, 12:18 AM
manowar689
the error for
Code:

`println()`
was
Code:

`cannot find symbol method println()`
and for
Code:

`println()`
the error was
Code:

`cannot find symbol method println(java.lang.String)`
hope this helps
• 06-24-2010, 12:54 AM
Norm
System.out.println(...) is so commonly used for debugging I didn't imagine that anyone wouldn't know how to use it.
• 06-24-2010, 01:02 AM
manowar689
i just wasnt too sure thats why i asked im pretty much self taught so the lingo gets me sometimes i did try that and gave the outputs of both in my last post
• 06-24-2010, 01:04 AM
manowar689
o sorry yes but this wouldnt solve my problem and the kdr.valgetint works fine in all my other programs
• 06-24-2010, 01:09 AM
Norm
Quote:

this wouldnt solve my problem
No.It doesn't.
It's to help you solve the problem. Its a technique called debugging. Many programmers use these kinds of techniques to solve their problems. First you need to understand what the program is doing, then you can change it to do what you want it to do.

Have you put the println() in the code and observed the output?
• 06-24-2010, 01:13 AM
manowar689
here are the files if you would like to try it and let me know lol
:confused:
• 06-24-2010, 02:13 AM
Norm
Sorry, not interested.