I am making a black jack program, as part of my goal to design and write at least one program a week, and I made 4 random variables with while loops to try and stop them from all being the same, and I cant figure out what I'm doing wrong, please help, thank you.

and it results:
Please enter initial bet in whole dollars: 1
Dealer is showing the King of Diamonds
Dealer is showing the King of Diamonds
Your are hiding the King of Diamonds and showing the King of Diamonds

i even tried changing it to generator.next.Int(1) + 1 but it still happened.

Edit: after some further testing I found out that it always goes to the highest case

05-28-2012, 03:17 PM

Norm

Re: Random variables are the same, whent they should be all different.

Can you make a small, simple program that compiles, executes and shows the problem by printing out the values that are "all being the same"? Post the code and its printed output.

Is your problem with the switch statement? You need to use a break statement to keep execution from falling through to the next case.

05-28-2012, 03:43 PM

JosAH

Re: Random variables are the same, whent they should be all different.

You forgot to add a 'break' at the end of each case clause (cases fall through in Java and C++ and C)

kind regards,

Jos

edit: I should've refreshed the page after I woke up ...

05-28-2012, 08:55 PM

Bitterguy

Re: Random variables are the same, whent they should be all different.

Quote:

Originally Posted by JosAH

You forgot to add a 'break' at the end of each case clause (cases fall through in Java and C++ and C)

kind regards,

Jos

edit: I should've refreshed the page after I woke up ...

Gahhh, thanks, I wanna kick myself after that one, I haven't messed with java since my class first semester haha. Gotta work the rust off :P