Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GussingGame {
- public static void main(String[] args) {
- int score = 0;
- int count = 0;
- int game = 0;
- int win = 0;
- int lose = 0;
- int selection = -1;
- Scanner input = new Scanner(System.in);
- System.out.println("Your score is " + win + " wins and " + lose + " losses");
- System.out.println("How many games do you want to play?");
- selection = input.nextInt();
- while (game != selection){
- while (count < 8){
- int number = (int)(Math.random() * 101);
- System.out.println("Guess a number between 0 and 100");
- int guess = 0;
- while (guess != number){
- System.out.print("\nEnter your guess: ");
- guess = input.nextInt();
- if (guess == number){
- System.out.println("Yes, the number is " + number);
- win++;
- game++;
- }
- else if (guess > number){
- System.out.println("Your guess is too high");
- count++;
- }
- else if (guess < number){
- System.out.println("Your guess is too low");
- count++;
- }
- if (count > 8){
- System.out.println("You lose");
- lose++;
- break;
- }
- }
- }
- System.out.println("Your score is " + win + " wins and " + lose + " losses");
- if (game == selection){
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement