Last active
January 21, 2017 07:28
-
-
Save tolmicl/23104cbb24a4ad391f8553a2d77710b1 to your computer and use it in GitHub Desktop.
Computer-Assisted Instruction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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