Skip to content

Instantly share code, notes, and snippets.

@tolmicl
Last active January 21, 2017 07:28
Show Gist options
  • Save tolmicl/23104cbb24a4ad391f8553a2d77710b1 to your computer and use it in GitHub Desktop.
Save tolmicl/23104cbb24a4ad391f8553a2d77710b1 to your computer and use it in GitHub Desktop.
Computer-Assisted Instruction
using System;
namespace p739
{
class p739
{
static void Main(string[] args)
{
while (true)
{
// create question and calculate correct answer
int answer = generateQuestion();
// get user answer
int user = Convert.ToInt32(Console.ReadLine());
// check if answers match
if (answer == user)
{
Console.WriteLine("Very good!");
}
else
{
Console.WriteLine("No. Please try again.");
do
{
user = Convert.ToInt32(Console.ReadLine());
} while (answer != user);
if (answer == user)
{
Console.WriteLine("Very good!");
}
}
}
}
static int generateQuestion()
{
Random random = new Random();
int one = random.Next(1, 10);
int two = random.Next(1, 10);
int answer = one * two;
Console.Write("How much is " + one + " times " + two + "? ");
return answer;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment