I'm making a C# console application for my college course and I've got an issue where I (or anybody else on the course) don't know what's wrong. In fact the tutor's not sure why it's happening. I'll show you part of the code to see if anyone can help. Probably a good idea to mention that I'm new to C# and programming in general.
static void Main(string[] args)
{
string userName = GetName();
int gradelevel = level();
double random1 = 0;
double random2 = 0;
int userChoice = menu();
int numberofquestions = 0;
string Message;
int userScore = 0;
do
{
if ((gradelevel == 1) && (userChoice == 1))//ADDITION LEVEL 1
{
generateSingleDigit(ref random1, ref random2);
double userAnswer = additionQuestion(ref random1, ref random2);
double Correctanswer = random1 + random2;
Message = checkAnswer(userAnswer, Correctanswer);
if (userAnswer == Correctanswer)
{
generatePositiveResponse();
userScore++;
}
else
{
int numberofAttempts = 1;
do
{
generateNegativeResponse();
userAnswer = additionQuestion(ref random1, ref random2);
Message = checkAnswer(userAnswer, Correctanswer);
numberofAttempts++;
} while ((numberofAttempts < 3) && (Message == "Incorrect"));
Console.WriteLine("The correct answer is {0}", Correctanswer);
}
}
numberofquestions++;
} while (numberofquestions <= 9);
percentage(ref userScore); `
The issue I'm having is that once the user has completed the 10 questions, the results from the percentage method briefly flash up and then the application closes itself. No "Press any key to continue" that I've seen in other applications I've made.
I would really appreciate any help on this. Thanks
If you add Console.ReadLine()
at the end, the window will stay open until you press the enter key. Otherwise, once it's completed, it'll close the command window.