455,806 Members | 1,380 Online
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

# Craps wins and losses

 P: 10 Hi, I'm writing a program that simulates 100 rounds of craps. I have the code written mostly. My one problem is that I can't seem to get the total numbers of wins and losses. Expand|Select|Wrap|Line Numbers import java.util.Random;   public class Test {       /**      * This Program show the results of simulated games of craps using if else statements      */     public static void main(String[] args) {         // TODO Auto-generated method stub         Random rand=new Random();         int xWon=0;         int xLost=0;         for(int i=1;i<=100;i++){             craps(rand);             if(true){                 xWon++;             }else{                 xLost++;             }         }System.out.println("Games Won: "+xWon);          System.out.println("Games Lost: "+xLost);     }         public static boolean craps(Random rand){         int dieI=rand.nextInt(6)+1;         int dieII=rand.nextInt(6+1);         int sumDies=dieI+dieII;             System.out.print("["+dieI+","+dieII+"]");               if (sumDies==7||sumDies==11){                 System.out.println(sumDies+" You Win!!!");                 return true;             } else if(sumDies==2||sumDies==3||sumDies==12){                 System.out.println(sumDies+" You Lose...");                 return false;         }         int point=sumDies;                 System.out.print("Point= "+point+" ");           do {             dieI=rand.nextInt(6)+1;             dieII=rand.nextInt(6+1);             sumDies=dieI+dieII;                 System.out.print("["+dieI+","+dieII+"]");         } while(sumDies!=7&&sumDies!=point);           if (sumDies==point){             System.out.println(sumDies+" You Win!!!");             return true;         } else{             System.out.println(sumDies+" You Lose...");             return false;         }         }   }   If someone could help me out that would be grand. I've been at this one part for 8 hours straight... Mar 6 '12 #1

When you're checking whether or not it was a win, you have to actually check the return value.
Expand|Select|Wrap|Line Numbers
1. if(craps(rand))