I'm trying to make a test on java. So far I'm on Question 1 and I'm having this issue. The if else statement won't allow me to add to the score.
class ExamEngine { static CinReader Cin= new CinReader(); static int Score=0; public static void main(String[] args) { System.out.println("Type in your name."); String name=Cin.readString(); System.out.println("Hello " +name+"."); System.out.println("Welcome to your Midterm."); System.out.println("Type in the correct word for the definition below."); System.out.println("Spelling counts, so make sure you spell the answer correctly."); Question1(); } public static void Question1() { System.out.println(" "); System.out.println("1. The operator (=) used to store the value of an expression into a variable, for instance"); System.out.println("variable = expression; The right-hand-side is completely evaluated before the assignment is made."); System.out.println(" An assignment may, itself, be used as part of an expression."); System.out.println("The following assignment statement stores zero into both variables. x = y = 0;"); String Q1=Cin.readString(); if(Q1.equals("assignment operator")) System.out.println("Good job!"); Score++; else{System.out.println("Incorrect."); } } }
If I remove the "Score++;" bit, everything is fine. But I need to add to the score when they answer a question right. However, with "Score++;" there, I get this issue: 'else' without 'if'.
Note that this cannot be multiple choice, so that's why I'm using if-else, because I don't think a case system would work here.
Is there a way I can make this work while adding to the score?