title: A global variable being subtracted incorrectly from another variable?
body: <p>Basically, I am creating a text-based simple casino program with Java. The problem I keep on running into is that whenever my betMoney variable is subtracted from my cash variable, it always does it incorrectly. Take a look at the game console:</p>
  
  <p>Hello and welcome to Vegas! Choose an amount of money from $0 to $10000 to begin (disregard commas)</p>
  
  <p>50</p>
  
  <p>Alright, now select the game you would like play:</p>
  
  <p>1) ROULETTE</p>
  
  <p>2) BLACK JACK</p>
  
  <p>1</p>
  
  <p>Time to play some roulette boi!</p>
  
  <p>How much money would you like to bet?</p>
  
  <p>50</p>
  
  <p>Choose what you would like to bet on</p>
  
  <p>1) COLOR</p>
  
  <p>2) NUMBER RANGE</p>
  
  <p>3) SPECIFIC NUMBER</p>
  
  <p>1</p>
  
  <p>What color would you like to bet on? </p>
  
  <p>1) RED (48.5% chance)</p>
  
  <p>2) BLACK (48.5% chance)</p>
  
  <p>3) GREEN (3% chance)</p>
  
  <p>1</p>
  
  <p>You bet on the wrong color! You now have $-50.0</p>
  
  <p>You still got money in the banks! Continue playing?</p>
  
  <p>And here's a snippet of my code that runs when a player wants to bet on color in roulette:</p>
  
  <pre><code>if (c == 1){
  
          if ((color % 2) == 0 &amp;&amp; color != 0){
              cash += betMoney;
              pr("You bet on the right color! You now have $"+ cash);
  
          }
          else{
              cash -= betMoney;
              pr("You bet on the wrong color! You now have $"+ cash);
  
          }
  </code></pre>
  
  <p>I am completely baffled by this error in my program. I can't seem to spot anything wrong with it. A player inputs their starting money, chooses how much money they want to bet, and what they want to bet on. If they lose, they lose the money they betted and it is subtracted from however much money they started with; simple as that, right? I guess not for me. Another problem I have been facing is that my program does not stop whenever cash &lt; 0. I've been going way into negative values for cash and my program does not pick up even though it is contained in a while loop that only continues if cash > 0:</p>
  
  <pre><code> while (cash &gt; 0){
  
      if (i == 0){    
          if (q == 1){
              roulette();
          }
          else{
              blackjack();
          }
  
          }
  
      else{
          pr("You still got money in the banks! Continue playing?");
          String choice = scan.next();
          if(choice.equalsIgnoreCase("yes")){
          pr("What game would you like to play?");
          pr("1) ROULETTE\n2) BLACK JACK");
          q = scan.nextInt();
          while(q != 1 &amp;&amp; q != 2){
              pr("Please pick a valid number");
              pr("1) ROULETTE\n2) BLACK JACK");
              q =  scan.nextInt();
          }
          if(q == 1){
              roulette();
          }
          else{
              blackjack();
          }   
      }
          else if(choice.equalsIgnoreCase("whip")){
              pr("NOW WATCH ME NAE NAE, OK");
              cash *= 10;
          }
          else{
              break;
          }
      }
      i++;
      }
  pr("You ended your streak with $"+ cash +".");
  }
  </code></pre>
  
  <p>Here's my full code:</p>
  
  <pre><code>    public static Scanner scan = new Scanner(System.in);
      public static Random rand = new Random();
      public static void pr(String q){
          System.out.println(q);
      }
      public static int i = 0;
      public static double cash;
  
      public static void main(String[] args) {
  
      pr("Hello and welcome to Vegas! Choose an amount of money from $0 to $10000 to begin (disregard commas)");
      double cash = scan.nextDouble();
      pr("Alright, now select the game you would like play:");
      pr("1) ROULETTE\n2) BLACK JACK");
  
      int q = scan.nextInt();
  
      //Ensures that the player chooses a valid option//
      while(q != 1 &amp;&amp; q != 2){
          pr("Please pick a valid number");
          pr("1) ROULETTE\n2) BLACK JACK");
          q =  scan.nextInt();
      }
  
      while (cash &gt; 0){
  
      if (i == 0){    
          if (q == 1){
              roulette();
          }
          else{
              blackjack();
          }
  
          }
  
      else{
          pr("You still got money in the banks! Continue playing?");
          String choice = scan.next();
          if(choice.equalsIgnoreCase("yes")){
          pr("What game would you like to play?");
          pr("1) ROULETTE\n2) BLACK JACK");
          q = scan.nextInt();
          while(q != 1 &amp;&amp; q != 2){
              pr("Please pick a valid number");
              pr("1) ROULETTE\n2) BLACK JACK");
              q =  scan.nextInt();
          }
          if(q == 1){
              roulette();
          }
          else{
              blackjack();
          }   
          }
          else if(choice.equalsIgnoreCase("whip")){
              pr("NOW WATCH ME NAE NAE, OK");
              cash *= 10;
          }
          else{
              break;
          }
          }
          i++;
          }
          pr("You ended your streak with $"+ cash +".");
      }
  
  
  
  
      public static void roulette(){
              int color = rand.nextInt(37);
              pr("Time to play some roulette boi!");
              pr("How much money would you like to bet?");
              double betMoney = scan.nextDouble();
              pr("Choose what you would like to bet on");
              pr("1) COLOR\n2) NUMBER RANGE\n3) SPECIFIC NUMBER");
              int q = scan.nextInt();
          while(q != 1 &amp;&amp; q != 2 &amp;&amp; q !=3){
              pr("Please pick a valid number");
              pr("1) COLOR\n2) NUMBER RANGE\n3) SPECIFIC NUMBER");
              q = scan.nextInt();
          }
  
          if (q ==1){
  
              pr("What color would you like to bet on? ");
              pr("1) RED (48.5% chance)\n2) BLACK (48.5% chance)\n3) GREEN (3% chance)");
              int c = scan.nextInt();
  
              while(c != 1 &amp;&amp; c != 2 &amp;&amp; c !=3){
                  pr("Please pick a valid number");
                  pr("1) RED (48.5% chance)\n2) BLACK (48.5% chance)\n3) GREEN (3% chance)");
                  c = scan.nextInt();
              }
              if (c == 1){
  
                  if ((color % 2) == 0 &amp;&amp; color != 0){
                      cash += betMoney;
                      pr("You bet on the right color! You now have $"+ cash);
  
                  }
                  else{
                      cash -= betMoney;
                      pr("You bet on the wrong color! You now have $"+ cash);
  
                  }
  
              }
              else if (c == 2){
                  if((color % 2) == 1 &amp;&amp; color != 0){
                      cash += betMoney;
                      pr("You bet on the right color! You now have $"+ cash);
  
                  }
                  else{
                      cash -= betMoney;
                      pr("You bet on the wrong color! You now have $" + cash);
  
                  }
              }
              else{
                      if (color == 0){
                          cash += (betMoney * 36);
                          pr("You bet on the correct color! You now have $" + cash);
  
                  }
                      else{
                          cash -= (betMoney);
                          pr("You bet on the wrong color! You now have $" + cash);
  
                      }
              }
  
  
          }
          if (q ==2){
              pr("What number range would you like to bet on?");
              pr("1) 0-12 (33% chance)\n2) 13-24 (33% chance)\n3) 25-36 (33% chance)");
              int c = scan.nextInt();
              while(c != 1 &amp;&amp; c != 2 &amp;&amp; c !=3){
                  pr("Please pick a valid number");
                  pr("1) 0-12 (33% chance)\n2) 13-24 (33% chance)\n3) 25-36 (33% chance)");
                  c = scan.nextInt();
              }
              if (c == 1){
                  if (color &gt;= 0 &amp;&amp; color &lt;= 12){
                      cash += (betMoney * 2);
                      pr("You bet on the right number range! The number was " + color + ". You now have $"+ cash);
  
                  }
                  else{
                      cash -= betMoney;
                      pr("You bet on the wrong number range! The number was " + color + ". You now have $" + cash);
  
                  }
  
              }
              else if (c == 2){
                  if (color &gt;= 13 &amp;&amp; color &lt;= 24){
                      cash +=  betMoney * 2;
                      pr("You bet on the right number range! The number was " + color +". You now have $" + cash);
                  }
                  else{
                      cash -= betMoney;
                      pr("You bet on the wrong number range! The number was " + color +". You now have $" + cash);
                  }
  
              }
              else if (c == 3){
                  if (color &gt;= 26 &amp;&amp; color &lt;= 36){
                      cash += betMoney * 2;
                      pr("You bet on the right number range! The number was " + color +". You now have $" + cash);
                  }
                  else {
                      cash -= betMoney;
                      pr("You bet on the wrong number range! The number was " + color + ". You now have $" + cash);
                  }
              }
  
          }
  
          else if (q ==3){
              pr("What number would you like to bet on? (Any integer from 0 - 36)");
              int c = scan.nextInt();
              while (c &lt; 0 &amp;&amp; c &gt; 36){
                  pr("Please input a valid number from 0 to 36 (inclusive)");
                  c = scan.nextInt();
              }
              if (color == c){
                  cash += betMoney * 36;
                  pr("The number is " + color + "!. You win $"+ betMoney * 36 +" and now have $"+ cash);
              }
              else{
                  cash -= betMoney;
                  pr("The number was "+ color + " not " + c +". You lose $" + betMoney +" and now have $"+ cash);
              }
          }
  
      }
      public static void blackjack(){
  
      }
      }
  </code></pre>