My program is a quiz. The questions start easy at level one questions when the user gets a question correct they go to a level two question, if they get this question correct they go to a level 3 question and so on. This is working correctly (except the beginning of the quiz when the program asks the user two level one questions for some reason before going to level two) However, the main problem is that when the user gets a question wrong the program doesn't go down the the previous level question and ask them another questions, the cursor just blinks repeatedly in the top right hand corner. This also happens when they reach the top level questions and get one correct (the program must be expecting level 6 questions but there is no level six questions). The questions are coming from a text file and there is 10 questions for each level so 50 questions in total. The questions are stored as a struct of strings in the text file the struct contains: Question Number Question Level Question Question Answer
Here is where the problem in the code lies. Please help, Thanks.
static void quiz(QuestionStruct[] _quiz)
{
bool asked = true;
int score = 0;
int AmountAsked = 0;
string level = "1";
string ans;
int pos = 1;
var pathToFile = @"..\..\..\Files\questions.txt";
using (StreamReader sr = new StreamReader(pathToFile, true))
{
while (AmountAsked < 20 || score >= 50)
{
Console.Clear();
string whatquestionnum = questions[pos].QuestionNum = sr.ReadLine();
string whatlevel = questions[pos].Level = sr.ReadLine();
//Level 1 questions
while (level == "1" && questions[pos].Level == level)
{
AmountAsked++;
string whatques = questions[pos].Question = sr.ReadLine();
Console.Write(whatques);
string selection = Console.ReadLine();
string decider = questions[pos].answer = sr.ReadLine();
if (selection == decider)
{
level = "2";
score = score + 1;
}
else
{
pos++;
}
}
//Level 2 questions
while (level == "2" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.Write(questions[pos].Question);
string selection2 = questions[pos].answer = sr.ReadLine();
ans = Console.ReadLine();
if (ans == selection2)
{
level = "3";
score = score + 2;
}
else
{
level = "1";
//questions[pos].Level == "1";
}
}
//Level 3 questions
while (level == "3" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.Write(questions[pos].Question);
string selection3 = questions[pos].answer = sr.ReadLine();
ans = Console.ReadLine();
if (ans == selection3)
{
level = "4";
score = score + 3;
}
else
{
level = "2";
}
}
//Level 4
while (level == "4" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.Write(questions[pos].Question);
string selection4 = questions[pos].answer = sr.ReadLine();
ans = Console.ReadLine();
if (ans == selection4)
{
level = "5";
score = score + 4;
}
else
{
level = "3";
}
}
//Level 5
while (level == "5" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.Write(questions[pos].Question);
string selection5 = questions[pos].answer = sr.ReadLine();
ans = Console.ReadLine();
if (ans == selection5)
{
level = "5";
score = score + 5;
}
else
{
level = "4";
}
}
}
}
}