having an issue with creating "choice" variable. I am trying to create a program which will ask you a math problem based upon selecting the type of problem.
Here is the program:
import java.util.Scanner;
public class BasicfourLoop {
public static void main(String[] args) {
final int NUMBER_OF_QUESTIONS = 5;
int correctCount = 0;
int count = 0;
int choice;
choice = 4;
long startTime = System.currentTimeMillis();
String output = " ";
Scanner input = new Scanner(System.in);
while (count < NUMBER_OF_QUESTIONS) {
int number1 = (int) (Math.random() * 100);
int number2 = (int) (Math.random() * 100);
if (number1 < number2) {
int temp = number1;
number1 = number2;
number2 = temp;
}
System.out.println("Enter your Choice:");
System.out.println("Enter 1 for Addition ");
System.out.println("Enter 2 for Subtraction ");
System.out.println("Enter 3 for Multiplication ");
System.out.println("Enter 4 for Division");
System.out.print("What is " + number1 + " + " + number2 + "? ");
int answer = input.nextInt();
if (number1 + number2 == answer) {
System.out.println("You are One Smart Cookie!!!");
correctCount++;
}
else
System.out.println("Your answer is stupid.\n" + number1 + " + " + number2 + " should be " + (number1 + number2));
System.out.print("What is " + number1 + " + " + number2 + "? ");
count++;
output += "\n" + number1 + "+" + number2 + "=" + answer + ((number1 + number2 == answer) ? " awesome" : " idiot");
}
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
System.out.println("Correct count is " + correctCount + "\nTest time is " + testTime / 1000 + " seconds\n" + output);
}
}
Please help!!!