|
-
November 11th, 2009, 10:16 PM
#1
Loop problem
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!");
}
}
-
November 12th, 2009, 06:19 AM
#2
Re: Loop problem
the pseudocode for a loop like that could be something like:
Code:
choice = user input
while choice != 'quit'
process choice
choice = user input
end while
I cannot teach anybody anything, I can only make them think...
Socrates
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|