I am currently working on a program that asks a student to answer 5 simple maths questions after each question it will state whether the answer is right or not.

which it will out put a grade and grade average percentage.

Currently I'm stuck on the if statement where it won't recognize my integer values and insists that they are strings
despite one being an actual int and the other being parsed from a string to an int.

So can someone point out what I'm doing wrong here?
Below is a snippet of what I have done so far
Any help is much appreciated! :)

String SumInput;

       int Answer,
           Sum,
           Num1,
           Num2;

       Answer = 0;
        Sum = 0;

        Sum = Integer.parseInt(SumInput);

       for (int sums = 0; sums <5; sums ++){

           Num1 = (int) (Math.random() * 10);
        Num2= (int) (Math.random() * 10); 

          SumInput = JOptionPane.showInputDialog("what is " + Num1 + " + " + Num2);

        Answer = Num1 + Num2;



        if (SumInput != Answer) {

          // space for JOption Input Dialog

            sums--;
        }

Try using .equals() instead. That should accurately compare the actual values of the two variables.

actually, what you are trying to do is not possible. you are trying to compare the value of a String to that of an int. it's like comparing a banana to the most expensive model of the latest BMW series.

if you want to compare them anyway, use the sum variable, and move this line of code:
Sum = Integer.parseInt(SumInput);
immediately after this one:
SumInput = JOptionPane.showInputDialog("what is " + Num1 + " + " + Num2);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.