jeudi 30 novembre 2017

Store random number and score

I just started programming for few days. I want to ask the user different questions and if they type in the right question then I will give them a score of 5 marks for getting the question right, plus bonus marks which are given by using Random, this bonus(Random) is then added to the total score(score(5) + random) which is stored and used to add the next score of the following question and the process repeats with all the questions[5]. This is what I have done so far, but it keeps printing the same result for every question and I want to keep adding to the previous score.

        for(int n = 0; n <QArray.length; n++)
        {
        System.out.println("Question" + (n+1));
        System.out.println(QArray[n]);

            for(int m =0; m<3; m++)
            {
            String ans = scanner.nextLine();    
            Random dice = new Random(); 
            int t = dice.nextInt(9) + 1; 
            int scoremarks = 5;  
              if (ans.equalsIgnoreCase(AArray[n]))
              {
              System.out.println("That is correct!\nYour score is:" + scoremarks + "\nWith bonus your total score is:" + (scoremarks +t));
              //correct = false;
              break;
              }
              else 
              {
              System.out.println("That is incorrect!\nYou got 0 Marks\nYour score is 0!");
              }




Aucun commentaire:

Enregistrer un commentaire