// Allison Obourn, CSE 142 // Prompts the user with addition puzzles comprised of // 2 - 5 operands until the user gets 3 wrong. import java.util.*; public class AdditionGame { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random rand = new Random(); int points = 0; int wrong = 0; while (wrong < 3) { int score = playRound(console, rand); points += score; if (score == 0) { wrong++; } } System.out.println("Points: " + points); } // creates an equation and prompts the user for a soultion // returns 1 if the user answers correctly and 0 otherwise public static int playRound(Scanner console, Random rand) { int operands = rand.nextInt(4) + 2; int value = rand.nextInt(10) + 1; System.out.print(value); int sum = value; for (int i = 1; i < operands; i++) { value = rand.nextInt(10) + 1; System.out.print(" + " + value); sum += value; } System.out.print(" = "); int guess = console.nextInt(); if (sum == guess) { return 1; } else { System.out.println("Wrong! The answer was " + sum); return 0; } } }