trying to see if i could get a little help with this program i am writing
"Write a complete program that plays a coin flipping game, displays the individual flips, reports when a game is “LOST” or “WON” and shows the number of flips needed to complete the game.
The algorithm is as follows:
• Simulate the flip of a coin using a JAVA random number generator.
• Flip the coin once to initialize the flip value and print out the flip
• Inside of a loop, repeatedly flip the coin until 3 consecutive flips have the same value (3 heads or 3 tails)
a. Display the flip results after each flip
• When the game ends, report the total number of flips
Note: you can use 0 for heads and 1 for tails, but if you have time, add another method that will convert the integers 0 and 1 to the characters ‘H’ and ‘T’"
This is what i got so far, but its not printing the right answer.
import java.util.*;
public class CoinFlip {
public static void main(String[] args) {
Random rand = new Random();
int H = 1;
int T = 0;
int Heads = 0;
int Tails = 0;
int tries = 0;
int result = rand.nextInt(0+1);
while(H != 3 || T !=3)
if (result == H){
H = H + 1;
System.out.println("Head");
Heads++;
}
else {
if (result == T && T <= 3){
T = T + 1;
System.out.println("Tail");
Tails++;
}
}
System.out.println(tries);
}
}
thanks for any help
This post has been edited by g00se: 09 March 2013 - 02:01 PM
Reason for edit:: Please use code tags

New Topic/Question
Reply



MultiQuote





|