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

public class RandomMathExample {
    
    public static void main(String[] args) {
        Scanner myScanner = new Scanner(System.in);
        Random myRandomGenerator = new Random();
        
        int solvedQuestions = 0;
        while (solvedQuestions < 5) {
            System.out.println("You have " + (5 - solvedQuestions) + " questions left.");
            
            //Get two number (0-99)
            int number1 = myRandomGenerator.nextInt(100);
            int number2 = myRandomGenerator.nextInt(100);
            
            System.out.println("What is " + number1 + " + " + number2 + "?");
            
            //get the user's answer and compare it to the proper answer
            int answer = myScanner.nextInt();
            if (answer == number1 + number2) {
                System.out.println("That's correct. Good job.");           
                solvedQuestions++; //increase completed questions
            }else{
                System.out.println("Ouch, you failed...");
                break; //stop asking questions
            }
        }
        System.out.println("You managed to solve " + solvedQuestions + " out of 5 questions.");
    }
    
}