jeudi 25 octobre 2018

Java math quiz. Keeps tally and scores but doesn't work and keep getting true as an answer

\ simple math quiz for school. needs a tally and how many questions to ask


import java.util.Scanner; import javax.swing.JOptionPane;

public class MathQuiz {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
// limits amnt of qs
int limit = 10;
int randomNumber1 =  (int)(20 * Math.random()) + 1;
int randomNumber2 =  (int)(20 * Math.random()) + 1;
int randomNumberAdd = randomNumber1 + randomNumber2;
int randomNumberMul = randomNumber1 * randomNumber2;
int randomNumberDiv = randomNumber1 / randomNumber2;
int randomNumberRem = randomNumber1 % randomNumber2;
double correct = 0;
String input = JOptionPane.showInputDialog(null, "Enter amount of 
questions: limit " + limit);

System.out.print( limit <=10);
  \\ gives answer but with true in front of the answer 

if (limit > 10) {
     System.out.println(" Too many questions. Try again");
 } else {
if (limit < 10) 
     System.out.println (" 888888");
} else {
     System.out.print(randomNumber1 + " + " + randomNumber2 + " = ");
int GuessRandomNumberAdd = keyboard.nextInt();

if (GuessRandomNumberAdd == randomNumber1 + randomNumber2) {
    System.out.println("Correct!");
correct++
}else {
 System.out.println("Try again!");
 System.out.println("The correct answer is " + randomNumberAdd);

}
System.out.print(randomNumber1 + " * " + randomNumber2 + " = ");    
int GuessRandomNumberMul = keyboard.nextInt();

if (GuessRandomNumberMul == randomNumber1 * randomNumber2) {
  System.out.println("Correct!");
  correct++;
}else{
    System.out.println("Try again!");
    System.out.println("The correct answer is " + randomNumberMul);


//math portion here the answer shows correctly but with the word true in front of it } System.out.print(randomNumber1 + " / " + randomNumber2 + " = "); int RandomNumberDiv = keyboard.nextInt();

if (RandomNumberDiv == randomNumber1 / randomNumber2) {
    System.out.println("Correct!");
    correct++;

    }else{
        System.out.println("Try again!");
        System.out.println("The correct answer is " + randomNumberMul);


}
    System.out.print(randomNumber1 + " % " + randomNumber2 + " = ");
    int GuessRandomNumberRem = keyboard.nextInt();
        if (GuessRandomNumberRem == randomNumber1 % randomNumber2) {
        System.out.println("Correct!");
        correct++;

        }else{
            System.out.println("Try again!!");
            System.out.println("The correct answer is " + randomNumberRem);
        }

\\ question tally 


System.out.println("You got " + correct + " correct answers.");
}
}

}




Aucun commentaire:

Enregistrer un commentaire