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.
If someone could help me out that would be grand. I've been at this one part for 8 hours straight...
Code:
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;
}
}
}
Comment