CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    17

    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) ;
            }
        }

  2. #2
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Subtraction Quiz Program

    It seems there is a + missing between number1 and "-".

  3. #3
    Join Date
    Jan 2012
    Posts
    17

    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
  •  





Click Here to Expand Forum to Full Width

Featured