I am doing a flashcard program using C# in which I need to display 2 single digit numbers and wait for the user to enter the answer. Then I need to display the score , which is numberCorrect/numberAttempted * 100. I have my program running fine right now, but the only problem is to do the counter for the numberCorrect and numberAttempted. I used do/while loop, and for whatever reason it only went through the loop once!!! HELP!!!
Code:
do
{
Random flashcard = new Random(); // create new random object
int a = flashcard.Next(0,10); // first number
int b = flashcard.Next(0,10); //second number
int answer;
int correct = 0;
int attempt = 0;
Console.Write(a + " + " + b + " = " );
input = Console.ReadLine();
//If the child enter q or Q, exit program
if ((input == "q") || (input == "Q"))
break;
//if answer correct, increment and diplay correct message.
//otherwise display incorrect message and the correct answer
answer = Int32.Parse(input);
if (answer == (a+b))
{
correct++;
attempt++;
Console.WriteLine("Corret! Good Job!");
}
else
{
attempt++;
Console.WriteLine("Wrong answer. The correct answer is " + (a+b));
}
Console.WriteLine("attempt = " + attempt);
Console.WriteLine("correct = " + correct);
//display score
Console.WriteLine("Score = " + Calculate(correct, attempt));
}
while ((input != "q") || (input != "Q"));