Java quiz issue -


i'm in little bit of problem. i've been doing java courses site: http://programmingbydoing.com/ , i've hit dead end on lesson: http://programmingbydoing.com/a/a-little-quiz.html.

i have no idea how keep track of answers, thought believe did right overall. been mashing brains on last couple of hours, please help. thanks.

import java.util.scanner;  public class quiz {     public static void main(string[] args)     {     scanner keyboard = new scanner(system.in);      string reply;     int answer;     int numberofquizes = 3;      int q1a1 = 1;     int q1a2 = 2;     int q1a3 = 3;     int q2a1 = 1;     int q2a2 = 2;     int q3a1 = 1;     int q3a2 = 2;     int q3a3 = 3;      system.out.print("are ready quiz?");     reply = keyboard.next();      system.out.println("okay, here comes!");     system.out.println("");     system.out.println("q1) capital of alaska?");     system.out.println("    "+ q1a1 +") melbourne");     system.out.println("    "+ q1a2 +") anchorage");     system.out.println("    "+ q1a3 +") jouneau");      system.out.print("your answer: ");     answer = keyboard.nextint();      if (answer == 1)     {         system.out.println("incorrect!");     }     else if (answer == 2)     {         system.out.println("incorrect!");     }     else if (answer == 3)     {         system.out.println("that's right!");     }     system.out.println();     system.out.println("q2) can store value \"cat\" in variable of type int?");     system.out.println("    "+ q2a1 +") yes");     system.out.println("    "+ q2a2 +") no");      system.out.print("your answer: ");     answer = keyboard.nextint();      if (answer == 1)     {         system.out.println("incorrect!");     }     else if (answer == 2)     {         system.out.println("that's right!");     }      system.out.println();     system.out.println("q3) result of 9+6/3?");     system.out.println("    "+ q3a1 +") 5");     system.out.println("    "+ q3a2 +") 11");     system.out.println("    "+ q3a3 +") 15/3");      system.out.print("your answer: ");     answer = keyboard.nextint();      if (answer == 1)     {         system.out.println("incorrect!");     }     else if (answer == 2)     {         system.out.println("that's right!");     }     else if (answer == 3)     {         system.out.println("incorrect!");     }      system.out.println();     system.out.println("overall, got x out of "+ numberofquizes +" ");     system.out.println("thanks playing!"); } 

}

use variable store correct answer count.

int correct = 0;

the inside if clause of correct answer:

system.out.println("that's right!"); correct = correct + 1; 

finally,

system.out.println("overall, got " + correct +" out of "+ numberofquizes +" ");


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -