• Check out the relaunch of our general collection, with classic designs and new ones by our very own Pissog!

Craps Java Program - [HELP]

Status
Not open for further replies.
Please note that I do NOT edit the 1st post with the updated program, please check the later post to see the current discussion on the program. Thanks.

Well I'm back and in need - yet again - of help with a program I'm trying to create. This program is meant to simulate a mini-craps game. There are some probems though...here's what it is at the moment:

Code:
//Job 35 rolldiceplus2.java
import java.util.*;

	class rolldiceplus2
   {
	public static void main (String[]args)
      {

	 System.out.println("The purpose of this program is to create random numbers which will simulate a rolling of dice.");
	 System.out.println();

		Scanner bob = new Scanner(System.in);

	// Create a random number maker
	   Random rMaker = new Random();

	 int bank = 1000;
	 int bet;
	 int win;
         int lose;

	// Ask for bet
	   System.out.println("You currently have $1000. How much would you like to bet?");
	   bet = bob.nextInt();
	   win = bank + bet;
  	   lose = bank - bet;

	   System.out.println();
{

	 int die1;
	 int die2;
	
	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;

	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);
	   System.out.println();

	// Add both die and place the value in a variable called roll
	   int roll = (die1 + die2);

	// Test for a winner (7 or 11)
	   if (roll == 7 || roll == 11)
	 
	   System.out.println("You Win! You now have " + win + " in your bank");

		else

	// Test for a loser (2, 3, or 12)
	   if (roll == 2 || roll == 3 || roll == 12)	 

	   System.out.println("You Lose! You now have " + lose + " in your bank");

		else
 	 	

	   System.out.println("Your point is " + roll);
	   System.out.println();

	// Initialize an integer vairable called point and assign it the value of roll
	   int point = roll;


	// Set up infinite while loop for more rolls
	   while (true)

 	   {
 
	   System.out.println("Push any letter key to roll again.");
	   String k = bob.nextLine();
	   System.out.println();

	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;

	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);

	// Add both die and place the value in a variable roll
	   roll = (die1 + die2);

	// Test for a winner
	   if (point == roll)
 	     {
	   System.out.println("You Win!");
	    break;
		}

	// Test for a loser
	   if (roll == 7 || roll == 11)
   	 {
	   System.out.println("You Lose");
	    break;
   	    }
      }
     }
	System.out.println("Game Over");
  }
}

When it gets to "Push any letter key to roll again" for some reason it skips it the 1st time and does the command by itself, THEN it allows the user to hit the key to continue. Do you know what the problem is?

Another thing that I want to add to the program (I've tried to figure out how, failed at finding it) is to give the user the option to "Quit" after any roll. I don't know how to make it jump out of the loop by typing in something (like "Quit" or "Stop" etc), anyone know how to?

One last thing is that I know I still have to make it ask for a bet inside the infinate loop, I want to figure that out myself but I figured it would be best to fix the current problem and add the "Quit" function before I continue.

Thanks.
-Matt
 
Well I'm back and in need - yet again - of help with a program I'm trying to create. This program is meant to simulate a mini-craps game. There are some probems though...here's what it is at the moment:

Code:
	   System.out.println("Push any letter key to roll again.");
	   String k = bob.nextLine();
	   System.out.println();

Another thing that I want to add to the program (I've tried to figure out how, failed at finding it) is to give the user the option to "Quit" after any roll. I don't know how to make it jump out of the loop by typing in something (like "Quit" or "Stop" etc), anyone know how to?


Try putting this in over the code left in the code box from your post.

Code:
System.out.println("Push any letter key and enter to roll again or type quit to quit.\n");
	   String k = bob.next();
           if(k.compareTo("quit")==0)
           {
               System.out.println("Qutting as requested.");
               break;
           }
	   System.out.println();
           }

Allows your user to quit by typing "quit". \n is a new line and less ugly than adding an empty System.out.println() to your code. Also seems to fix the first run through of the while loop bug for me.
 
Ok I did that but when I compile I get:

Code:
rolldiceplus2.java:124: (identifier) expected
                 System.out.println("Game Over");
                                   ^
rolldiceplus2.java:126: 'class' or 'interface' expected
}
^

rolldiceplus2.java:126: 'class' or 'interface' expected
}
  ^

3 errors

I don't know what the :::::'class' or interface'::::: part means, or the :::::(identifier):::::.
 
why do you have a seemingly random { beneath the section of code that asks for a bet? i've never used java but it looks like those braces are what's causing your errors.

proper spacing is often key to debugging a program

stuff like this:
Code:
    // Initialize an integer variable called point and assign it the value of roll
    int point = roll;
is what's known as a "useless comment". try to comment your code with its function - describe what "point" and "roll" represent


to clarify, here's what i believe should be removed:
Code:
..............

    // Ask for bet
       System.out.println("You currently have $1000. How much would you like to bet?");
       bet = bob.nextInt();
       win = bank + bet;
         lose = bank - bet;

       System.out.println();
{ <---------------------------------------this

     int die1;
     int die2;
    
.............


    // Test for a loser
       if (roll == 7 || roll == 11)
        {
       System.out.println("You Lose");
        break;
           }
      }
     } <----------------------------------------this
    System.out.println("Game Over");
  }
}


oh and you may need a semicolon after the class declaration. again, not too hot on java but that's how it's done in c++
 
To put the entire rolling sequence into a single section, however I don't think I meant to put it there, it's where they roll over and over that I need it so it was just misplaced.
 
To try to solve the problem you told me about in your PM, try inserting this line exactly before the while (true) command:

Code:
bob.nextLine();
 
Trax: Still haven't figured out what makes it go wrong with what you told me to do, it runs before I do it but not after, same errors come up.

m0nkfish: Thanks for pointing that out. I'll add those comments once I get it all to work right >.<

X-Act: Thank you very much for that. Um 2 things: 1) Why did it do that and why did what you did fix it (I like to understand what goes on so that I know next time) and 2) Do you know how to give the user the option to "Quit" or "Stop" by typing said word and jump out of the loop?
 
Do you know how to give the user the option to "Quit" or "Stop" by typing said word and jump out of the loop?

You'd have to change your while loop to only run while your 'k' variable is not equal to 'quit' or 'stop'. I'm a bit of an amateur myself and don't know now exactly to get if a string does not equal something, but you could always make it so it loops while 'k' is equal to 'roll', and if the user inputs anything else it jumps out.

Hope that helped.
 
to break out of the loop when the user enters "quit", insert this into your while loop, just after you get the user input:
Code:
if (k.equals("quit")) {
  break;
}
 
Drop the last } from my code box and it'll work, I copied one line too many ><

Basically what's happened is that the class is getting closed off by the addition of that } (probably on the next } or the one after).

edit:

Correct code

Code:
           System.out.println("Push any letter key and enter to roll again or type quit to quit.\n");
	   String k = bob.next();
           if(k.compareTo("quit")==0)
           {
               System.out.println("Qutting as requested.");
               break;
           }
	   System.out.println();

Edit: Xact, that will (sort of) work, problem is that when you do that his program stalls with no explanation so he'd need more stuff printed.
 
Another problem...of course lol. Current program:

Code:
//Job 35 rolldiceplus2.java
import java.util.*;

	class rolldiceplus2
   {
	public static void main (String[]args)
      {

	 System.out.println("Welcome to the craps table!");
	 System.out.println();

		Scanner bob = new Scanner(System.in);


	// Create a random number maker
	   Random rMaker = new Random();

	 int balance = 1000;
	 int bank = balance;
	 int bet;
	 int win;
         int lose;


	// Ask for bet
	   System.out.println("You currently have $" + bank + ". How much would you like to bet?");
	   bet = bob.nextInt();
	   win = balance + bet;
           lose = balance - bet;
	   System.out.println();


	 int die1;
	 int die2;
	

	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);
	   System.out.println();


	// Add both die and place the value in a variable called roll
	   int roll = (die1 + die2);


	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
 	 System.out.println("You Win! You now have $" + bank + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
	    System.out.println("You Lose! You now have $" + bank + " in your bank\n");
	  }
	  else {
 	   balance = balance;
 	   System.out.println("Your point is " + roll + "\n");
	  }
	}


	// Initialize an integer vairable called point and assign it the value of roll
	   int point = roll;



	// Set up infinite while loop for more rolls
	   bob.nextLine();
	   while (true)

 	   {
 
	   System.out.println("Push a key to roll again. Or you can end the game, type quit to end game.\n");
	   String k = bob.next();
           if(k.compareTo("quit")==0)
           {
               System.out.println("Qutting as requested.");
               break;
           }
	   System.out.println();
	
	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);


	// Add both die and place the value in a variable roll
	   roll = (die1 + die2);


	// Test for a winner
	   if (point == roll)
 	     {
	   System.out.println("You Win!");
	    break;
		}


	// Test for a loser
	   if (roll == 7 || roll == 11)
   	 {
	   System.out.println("You Lose");
	    break;
   	    }
      }
     
	System.out.println("Game Over!");
  }
}

Now when I win on the 1st roll (by rolling a 7 or 11) instead of breaking out of it and saying you win, game over, it continues on to the infinate loop.
 
Something like this:

Add a variable: boolean loopbreak = true;

Then change your initial roll win/loss tests like this

Code:
	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
         loopbreak = false;
 	 System.out.println("You Win! You now have $" + bank + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
            loopbreak = false;
	    System.out.println("You Lose! You now have $" + bank + " in your bank\n");
	  }
	  else {
 	   balance = balance;
 	   System.out.println("Your point is " + roll + "\n");
	  }
	}

p.s. the balance = balance is useless.

Then use this line to initiate your while loop:
Code:
 while (loopbreak == true)

You can continue to use break; in your loop to stop it and it does the same thing - except for quitting, you need break; when quitting so it doesn't go and roll again for no purpose because if you set the while variable to false the loop completes its current run before hitting the while statement again.
 
Code:
C:\Jobs\Jobs\Job 35>javac rolldiceplus2.java
rolldiceplus2.java:54: cannot find symbol
symbol  : variable loopbreak
location: class rolldiceplus2
         loopbreak = false;
         ^
rolldiceplus2.java:61: cannot find symbol
symbol  : variable loopbreak
location: class rolldiceplus2
            loopbreak = false;
            ^
rolldiceplus2.java:77: cannot find symbol
symbol  : variable loopbreak
location: class rolldiceplus2
        while (loopbreak == true)
               ^
3 errors

C:\Jobs\Jobs\Job 35>

IDK what's wrong with it now....I replaced only what you said to, so..*shrugs*
 
Did you add a variable called loopbreak?

Just chuck under your variable declarations at the start.
boolean loopbreak = true;

Also, what environment are you using? O.o
 
1) I'm new to programming...so you're gonna have t tell me what an environment is (I might know just not by that term).

2) I'm having difficulty with the balance/bank/bet...here's what I have in the code:

Code:
	 int balance = 1000;
	 int bank = balance;
	 int bet;
	 int win;
         int lose;
	 boolean loopbreak = true;

.......................................

	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
         loopbreak = false;
 	 System.out.println("You Win! You now have $" + bank + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
            loopbreak = false;
	    System.out.println("You Lose! You now have $" + bank + " in your bank\n");
	  }
	  else {
 	   System.out.println("Your point is " + roll + "\n");
	  }
	}

Currntly, when you win the bet doesn't get added and when you lose it doesn't get subtracted.
 
So the loop is working now I assume.

Onto your new problem..

In java when you say bank = balance and leave it at that, because it's a primitive data type (like int, char, boolean etc) it'll just set bank = whatever balance is, but won't update the value of bank when you change balance.

To be entirely honest I'm not sure of the purpose for having 2 variables there.. I'd do it something like this code box below. If it's in your requirements, you just have to add bank = balance after any updates to balance (in your code), but that's a freaking dumb requirement seeing as they're both used for *exactly* the same task so far as I can see.

Code:
         int balance = 1000;
	 int bet;
	 int win;
         int lose;
	 boolean loopbreak = true;

.......................................

	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
         loopbreak = false;
 	 System.out.println("You Win! You now have $" + balance + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
            loopbreak = false;
	    System.out.println("You Lose! You now have $" + balance + " in your bank\n");
	  }
	  else {
 	   System.out.println("Your point is " + roll + "\n");
	  }
	}

Environment meaning "whatever you're writing the code in" (e.g. what program). Your error messages look familiar but I can't remember where from!
 
Well I set it up in a double variable because I wasn't sure if I would need to later...I'll explain that in a minute.

Uh I type them up in Notepad and run them on the Command Prompt (is that what you wanted to know?).

Here's the "plan" i'm doing with the craps program.

I'm writing a big program that will simulate a casino, the 1st game I chose to make was craps, then blackjack and finaly a slot machine. The beggining of the big program will be "Welcome to the casino, please type one of the following to play the game: Craps, Blackjack, or Slots." then make it to where when they type the word it takes them to that part of the program and lets them go through it. They can then either "Quit" and go back to the main menu to pick another game. The program exits the loop when they hit $0 and the begin with $1000. I used bank = balance because I thought I might need to do that to link up the bank/balance to all of the games inside the program...

Here's how I THINK it'll be set up (not sure if this will run right when I finish everyhing):

Code:
//job casino casino.java
import java.util.*;

	class casino
   {
	public static void main (String[]args)
      {

	   int balance = 1000;
	   int bank = balance;
	   int bet;
	   int win = balance + bet;
	   int lose = balance - bet;

 	 System.out.println();
	 System.out.println("Welcome to the GHS Casino Game!");	
	 System.out.println("You currently have $"  + bank + ".");
	 System.out.println("Once you hit $0, you LOSE!\n");

		Scanner bob = new Scanner(System.in);


	// Give user list to choose from
	    while (balance > 0)
	{
	 System.out.println("Please type in the game you would like to play!");
 	 System.out.println("Type one of the following:");
 	 System.out.println("Blackjack, Craps, or Slots.\n");
	   **********LINK WORDS TO PROGRAM**********
 	 System.out.println();



	**********BLACKJACK PROGRAM GOES HERE**********

	**********CRAPS PROGRAM GOES HERE**********

	**********SLOTS PROGRAM GOE HERE**********



	// Loop back to beggining unless they run out of money
	   if (balance < 0)
	   break;
	}

 	 System.out.println("Game Over!");
  }
}

Obviously the stars will be changed once I finish/figure out that part. So do I need a double variable like bank = balance to make that work or not?
 
Obviously the stars will be changed once I finish/figure out that part. So do I need a double variable like bank = balance to make that work or not?

Unless for some reason your bank and balance figures need to be different at some point for whatever reason, there's no reason to have two.

Also ouch, writing java in notepad / cmd prompt, I'd go nuts doing that!
 
how else can you do it???? that's how we do it in class so...also do you think this can work as it is presented?:

Code:
//job casino casino.java
import java.util.*;

	class casino
   {
	public static void main (String[]args)
      {

	   int balance = 1000;
	   int bank = balance;
	   int bet;
	   int win = balance + bet;
	   int lose = balance - bet;

 	 System.out.println();
	 System.out.println("Welcome to the GHS Casino Game!");	
	 System.out.println("You currently have $"  + bank + ".");
	 System.out.println("Once you hit $0, you LOSE!\n");

		Scanner bob = new Scanner(System.in);


	// Give user list to choose from
	    while (balance > 0)
	{
	 System.out.println("Please type in the game you would like to play!");
 	 System.out.println("Type one of the following:");
 	 System.out.println("Blackjack, Craps, or Slots.\n");
	   **********LINK WORDS TO PROGRAM**********
 	 System.out.println();



	**********BLACKJACK PROGRAM GOES HERE**********

	**********CRAPS PROGRAM GOES HERE**********

	**********SLOTS PROGRAM GOE HERE**********



	// Loop back to beggining unless they run out of money
	   if (balance < 0)
	   break;
	}

 	 System.out.println("Game Over!");
  }
}

Do you know how to make it go to the Craps section when they type in "craps" or the blackjack one when they type in "blackjack"? Also, just to be clear: I can just use bank/balance and it will carry the current amount all the way right?
 
To answer the question about structure..

Code:
//job casino casino.java
import java.util.*;

	class casino
   {
	public static void main (String[]args)
      {

	   int balance = 1000;
	   int bank = balance;
	   int bet;
	   int win = balance + bet;
	   int lose = balance - bet;

 	 System.out.println();
	 System.out.println("Welcome to the GHS Casino Game!");	
	 System.out.println("You currently have $"  + bank + ".");
	 System.out.println("Once you hit $0, you LOSE!\n");

		Scanner bob = new Scanner(System.in);


	// Give user list to choose from
	    while (balance > 0)
	{
	 System.out.println("Please type in the game you would like to play!");
 	 System.out.println("Type one of the following:");
 	 System.out.println("Blackjack, Craps, or Slots.\n");
	   **********LINK WORDS TO PROGRAM**********
       String x = bob.next();

 	 System.out.println();



	if(x.compareTo("Blackjack")==0)
           {
               <Blackjack Stuff>
           }

	else if(x.compareTo("Craps")==0)
           {
               <Craps Stuff>
           }

	else if(x.compareTo("Slots")==0)
           {
               <Slots Stuff>
           }

        else
           {
               System.out.println("Please enter Slots, Craps or Blackjack!");
           }

	// Loop back to beggining unless they run out of money
	   if (balance < 0)
	   break;
	}

 	 System.out.println("Game Over!");
  }
}


Something like that.

If you don't change a variable somehow it won't change, so should carry forever.

I edit my Java in "NetBeans" IDE - not especially good but it is easier than notepad / DOS - it's one heck of a download though.
 
Ok thanks. Back to Craps..>.>

Code:
//Job 35 rolldiceplus2.java
import java.util.*;

	class rolldiceplus2
   {
	public static void main (String[]args)
      {

	 System.out.println("Welcome to the craps table!");
	 System.out.println();

		Scanner bob = new Scanner(System.in);


	// Create a random number maker
	   Random rMaker = new Random();

	 int balance = 1000;
	 int bet;
	 boolean loopbreak = true;


	// Ask for bet
	   System.out.println("You currently have $" + balance + ". How much would you like to bet?");
	   bet = bob.nextInt();
	   System.out.println();


	 int die1;
	 int die2;
	

	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);
	   System.out.println();


	// Add both die and place the value in a variable called roll
	   int roll = (die1 + die2);


	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
         loopbreak = false;
 	 System.out.println("You Win! You now have $" + balance + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
            loopbreak = false;
	    System.out.println("You Lose! You now have $" + balance + " in your bank\n");
	  }
	  else {
 	   System.out.println("Your point is " + roll);
	  }
	}

	// Initialize an integer vairable called point and assign it the value of roll
	   int point = roll;



	// Set up infinite while loop for more rolls
	   bob.nextLine();
	while (loopbreak == true)

 	   {

	   System.out.println();
	   System.out.println("Press any key to continue. Or you can end the game, type quit to end game.\n");
	   String k = bob.next();
           if(k.compareTo("quit")==0)
           {
               System.out.println("Qutting as requested.");
               break;
           }
	   System.out.println();
	
	// Ask for bet
	   System.out.println("You currently have $" + balance + ". How much would you like to bet?");
	   bet = bob.nextInt();
	   System.out.println();

	
	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);


	// Add both die and place the value in a variable roll
	   roll = (die1 + die2);


	// Test for a winner
	   if (point == roll){
	    balance = balance + bet;
 	     
	   System.out.println("You Win. You now have $" + balance + " left in your bank");
	   
		}


	// Test for a loser
	   if (roll == 7 || roll == 11){
	    balance = balance - bet;
   	 
	   System.out.println("You Lose. You now have $" + balance + " left in your bank");
	    
	// Break from the loop
	   if (balance < 0){
	   break;
	       }
   	    }
      }
     
	System.out.println("Game Over!");
  }
}

Ok I tried an IF statment to jump out of the loop once the user hits 0 in balance but it's not working...also I need to make it continue even if you win on the first roll...
 
Ok I tried an IF statment to jump out of the loop once the user hits 0 in balance but it's not working...also I need to make it continue even if you win on the first roll...

Code:
if (balance < 0){
	   break;
	       }

That only breaks if the balance is LESS than 0 (i.e. it won't break **on** 0).

Try

Code:
if (balance <= 0){
	   break;
	       }
 
OMG I feel so stupid not thinking about that....lol...ok thank you.

Before I ask the next Q, I wanna know something. You said that it would drive you nuts to use Comand Prompt and Notepad, well how do YOU do it then?

And here's the code (problem explained below it):

Code:
//Job 35 rolldiceplus2.java
import java.util.*;

	class rolldiceplus2
   {
	public static void main (String[]args)
      {

	 System.out.println("Welcome to the craps table!");
	 System.out.println();

		Scanner bob = new Scanner(System.in);


	// Create a random number maker
	   Random rMaker = new Random();

	 int balance = 1000;
	 int bet;
         boolean loopbreak = false;

	// Ask for bet
	   System.out.println("You currently have $" + balance + ". How much would you like to bet?");
	   bet = bob.nextInt();
	   System.out.println();


	 int die1;
	 int die2;
	

	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);
	   System.out.println();


	// Add both die and place the value in a variable called roll
	   int roll = (die1 + die2);


	if (roll == 7 || roll == 11) {
 	 balance = balance + bet;
         loopbreak = false;
 	 System.out.println("You Win! You now have $" + balance + " in your bank\n");
	}
	else {
  	// Test for a loser (2, 3, or 12)
 	 if (roll == 2 || roll == 3 || roll == 12) {  
	    balance = balance - bet;
            loopbreak = false;
	    System.out.println("You Lose! You now have $" + balance + " in your bank\n");
	  }
	else
	// Break if you hit 0 balance
	 if (balance <= 0){
	    loopbreak = false;
	}

	  else {
 	   System.out.println("Your point is " + roll);
	  }
	}

	// Initialize an integer vairable called point and assign it the value of roll
	   int point = roll;


	// Set up infinite while loop for more rolls
	   bob.nextLine();
	while (loopbreak = true)

 	   {

	   System.out.println();
	   System.out.println("Press any key to continue. Or you can end the game, type quit to end game.\n");
	   String k = bob.next();
           if(k.compareTo("quit")==0)
           {
               System.out.println("Qutting as requested.");
               break;
           }
	   System.out.println();
	
	// Ask for bet
	   System.out.println("You currently have $" + balance + ". How much would you like to bet?");
	   bet = bob.nextInt();
	   System.out.println();

	
	// Roll 1st die
	   die1 = rMaker.nextInt(6)+1;


	// Roll 2nd die
	   die2 = rMaker.nextInt(6)+1;

	   System.out.println("You rolled a " + die1 + " and a " + die2);


	// Add both die and place the value in a variable roll
	   roll = (die1 + die2);


	// Test for a winner
	   if (point == roll){
	    balance = balance + bet;
 	     
	   System.out.println("You Win. You now have $" + balance + " left in your bank");
	   
		}


	// Test for a loser
	   if (roll == 7 || roll == 11){
	    balance = balance - bet;
   	 
	   System.out.println("You Lose. You now have $" + balance + " left in your bank");
	    
	// Break from the loop
	   if (balance <= 0){
	   break;
	       }
   	    }
      }
     
	System.out.println("Game Over!");
  }
}

I put the following code in:

Code:
	// Break if you hit 0 balance
	 if (balance <= 0){
	    loopbreak = false;
	}

Right before the while loop to try to stop it from entering it if you hit 0 on the 1st roll (like if you bet 1000 and roll a losing roll) but it ddn't work...do you know what I did wrong or what I should have done instead?


EDIT: One more Question: Do you know a better way to do this: I have it where they punch in a key then enter to continue, do you know a better way or is that about the best way to make the loop stop and let the user control when it goes?
 
Status
Not open for further replies.
Back
Top