|
-
July 17th, 2012, 04:03 PM
#1
Subtraction Quiz Program
Having a problem with my Subtraction Quiz program on a specific line!
Code:
output += "\n" + number1 "-" + number2 + "=" + answer + ((number1 - number2 == answer) ? " correct" : " wrong") ;
The rest of the program seems to work except that output. It gives an error of " ';' expected "
Code Here:
Code:
public static void main(String[] args)
{
final int NUMBER_OF_QUESTIONS = 10 ;
int correctCount = 0 ;
int count = 0 ;
long startTime = System.currentTimeMillis() ;
String output = "" ;
Scanner input = new Scanner(System.in) ;
while(count < NUMBER_OF_QUESTIONS) {
int number1 = (int)(Math.random() * 15) ;
int number2 = (int)(Math.random() * 15) ;
if(number1 < number2) {
int temp = number1 ;
number1 = number2 ;
number2 = temp ;
}
System.out.print("What is " + number1 + " - " + number2 + "?") ;
int answer = input.nextInt() ;
if(number1 - number2 == answer) {
System.out.println("You are correct!") ;
correctCount++ ;
} else {
System.out.println("Your answer is wrong. \n" + number1 + " - " + number2 + " should be " + (number1 - number2)) ;
count++ ;
output += "\n" + number1 "-" + number2 + "=" + answer + ((number1 - number2 == answer) ? " correct" : " wrong") ;
}
long endTime = System.currentTimeMillis() ;
long testTime = endTime - startTime ;
System.out.println("Current count is " + correctCount + "\nTest time is " + testTime / 1000 + " seconds\n" + output) ;
}
}
-
July 18th, 2012, 12:27 PM
#2
Re: Subtraction Quiz Program
It seems there is a + missing between number1 and "-".
-
July 18th, 2012, 12:36 PM
#3
Re: Subtraction Quiz Program
Ahh cheers thank you! I hate when the problem is as trivial as that! It makes the thread very pointless!
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|