473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Craps wins and losses

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
  1. import java.util.Random;
  2.  
  3. public class Test {
  4.  
  5.     /**
  6.      * This Program show the results of simulated games of craps using if else statements
  7.      */
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         Random rand=new Random();
  11.         int xWon=0;
  12.         int xLost=0;
  13.         for(int i=1;i<=100;i++){
  14.             craps(rand);
  15.             if(true){
  16.                 xWon++;
  17.             }else{
  18.                 xLost++;
  19.             }
  20.         }System.out.println("Games Won: "+xWon);
  21.          System.out.println("Games Lost: "+xLost);
  22.     }    
  23.     public static boolean craps(Random rand){
  24.         int dieI=rand.nextInt(6)+1;
  25.         int dieII=rand.nextInt(6+1);
  26.         int sumDies=dieI+dieII;
  27.             System.out.print("["+dieI+","+dieII+"]");
  28.  
  29.             if (sumDies==7||sumDies==11){
  30.                 System.out.println(sumDies+" You Win!!!");
  31.                 return true;
  32.             } else if(sumDies==2||sumDies==3||sumDies==12){
  33.                 System.out.println(sumDies+" You Lose...");
  34.                 return false;
  35.         }
  36.         int point=sumDies;
  37.                 System.out.print("Point= "+point+" ");
  38.  
  39.         do {
  40.             dieI=rand.nextInt(6)+1;
  41.             dieII=rand.nextInt(6+1);
  42.             sumDies=dieI+dieII;
  43.                 System.out.print("["+dieI+","+dieII+"]");
  44.         } while(sumDies!=7&&sumDies!=point);
  45.  
  46.         if (sumDies==point){
  47.             System.out.println(sumDies+" You Win!!!");
  48.             return true;
  49.         } else{
  50.             System.out.println(sumDies+" You Lose...");
  51.             return false;
  52.         }
  53.  
  54.  
  55.     }
  56.  
  57. }
  58.  
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

✓ answered by Rabbit

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))

2 2625
Rabbit
12,516 Expert Mod 8TB
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))
Mar 6 '12 #2
rsduck
10
Thank-you so much! I literally tried everything except that.
Mar 6 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
1
by: nemesis | last post by:
help!!! IMy problem is that I don't know how to make the increase/decrease part work. The specification given to me by my teacher was: if the layer wins, double the wager (done!), and if loses ,...
1
by: lblock | last post by:
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and...
2
by: mer000 | last post by:
Can you guys help me out? I'm trying to create a very simple game of craps but having some trouble. Below are the rules and requirements. Much appreciated! Given the following rules for the game...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
1
by: Shark2026 | last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it. In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
18
by: Rhodge09 | last post by:
This is my script it works fine but it comes out on my webpage as just text how can i change this around and make it so if i like click a button a 2 different numbers come up almost like the 2 dice...
3
by: boardwiz | last post by:
On the youtube video "best winning craps system # 1 the guy say you can play Craps like it were Chess. Is this true?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.