Я выполняю задание на программирование, которое задает пользователю несколько вопросов. Если пользователь получает неправильный / правильный ответ, это не имеет значения, и для определения их баллов за этот вопрос используется генератор случайных чисел. Однако, если они выбирают «невозможный ответ» (что-то, чего не может быть, их счет сбрасывается до 0.
Когда я запускаю код,
Если я получу 23 баллапервые вопросы и 0 на втором, это должно сбросить мой счет до 0 на втором вопросе, но в конце общий балл будет показан как 23.
Любая помощь будет оценена
import java.util.Scanner;
public class Main {
public static double randnum(){
int random = (int)(Math.random() * 50 + 1);
return random;
}
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int score1 = 0;
int score2 = 0;
int score3 = 0;
int totalscore = 0;
final double NumberofQuestions = 2;
String[][] questions ={
{"What is the largest bone in the human body? ", "\n Choose 1 for Femur \n Choose 2 for Tibia \n Choose 3 for Palatine Bone \n Choose 4 for Tongue ", "1"},
{"What is the capital of Albania? ! ","\n Choose 1 for Shkoder \n Choose 2 for Tirana \n Choose 3 for Durres \n Choose 4 for Rome ", "2"}
};
String[] Answers = new String[(int) NumberofQuestions];
int x=0;
do
{
System.out.print("" + (x+1) + ". " + questions[x][0] + " "+questions[x][1]);
Answers[x] = String.valueOf(input.nextInt());
Answers[x].toLowerCase();
if(questions[x][2].equals(Answers[x])) {
score1 = (int) randnum();
System.out.println("Correct: " + score1 + " points");
totalscore = totalscore + score1;
}
if (Answers[x].equals("4")){
System.out.println("\n Thats a impossible answer! The right answer is "+questions[x][2]);
totalscore = 0;
score2 = 0;
System.out.println(score2 + " points");
} else {
System.out.println("\nIncorrect. The right answer is "+questions[x][2]);
score3 = (int) randnum();
System.out.println(score3 + " points");
totalscore = totalscore + score3;
}
System.out.print("\n");
x++;
} while(x < NumberofQuestions); //close outer loop
totalscore = score1 + score2 + score3;
System.out.println("\n\t\tYou got " + totalscore + " points !\n\n\n");
System.exit(0);
}
}