Click to See Complete Forum and Search --> : Loop problem


ryan449
November 11th, 2009, 09:16 PM
Hey im alittle stuck with this quick rock paper scissors game what i have to make the loop so that it will replay the game over and over until the user wants to quit then it will print the number of games won loss and teid. can someone help me out. here is the code



import java.util.Random;
import java.util.Scanner;

public class Rpc
{

public static void main(String[] args)

{

int yourchoice;
int compchoice;

//Get the choice from the player
Scanner scan = new Scanner (System.in);

System.out.println ("Rock, Paper, or Scissors? ");
System.out.println ("1 for Rock, 2 for Paper, 3 for Scissors ");
yourchoice = scan.nextInt();

//Gets the Computers choice
Random randomnum = new Random ();

compchoice = randomnum.nextInt(3);

//All the if statements
if (yourchoice == 1 && compchoice == 0)
System.out.println( "Tie!");

else if (yourchoice == 1 && compchoice == 1)
System.out.println("Paper beats rock. You lose!");

else if (yourchoice == 1 && compchoice == 2)
System.out.println("Rock beats scissors. You win!");

else if (yourchoice == 2 && compchoice == 0)
System.out.println("Paper beats rock. You win!");

else if (yourchoice == 2 && compchoice == 1)
System.out.println("Tie!");

else if (yourchoice == 2 && compchoice == 2)
System.out.println("Scissors beats paper. You lose!");

else if (yourchoice == 3 && compchoice == 0)
System.out.println("Rock beats Scissors. You lose!");

else if (yourchoice == 3 && compchoice == 1)
System.out.println("Scissors beats paper. You win!");

else if (yourchoice == 3 && compchoice == 2)
System.out.println("Tie!");


}


}

dlorde
November 12th, 2009, 05:19 AM
the pseudocode for a loop like that could be something like:choice = user input
while choice != 'quit'
process choice
choice = user input
end whileI cannot teach anybody anything, I can only make them think...
Socrates