Thread: Counter
View Single Post
Old 10-04-2004, 05:12 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
you are setting 'correct' and 'attempt' to 0 each time the values go through the loop. put those lines of code above the 'do'. also, we have tags which make code easier to read here. [code ] [/code ] ( without the spaces.

look at the top before the do loop. i think this will solvey our problem.
Code:
int answer;
int correct = 0; 
int attempt = 0;

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

	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"));
__________________
Mike
sde is offline   Reply With Quote