Help me fully explain this code please.


Joined
Jan 14, 2020
Messages
1
Reaction score
0
using System;
namespace ConsoleApp2
{
class Program
{
static void DispMenu()
{
Console.WriteLine("[1] Start\n[2] Instructions");
Console.Write("Enter your choice: ");
}
static void Main(string[] args)
{
Random numberGenerator = new Random();
int PCount = 0;
int QCount = 0;
int iScore = 0;
int iCount = 0;
int iChoice;

while (iCount == 0)
{
DispMenu();
iChoice = int.Parse(Console.ReadLine());

if (iChoice == 1)
{
Console.WriteLine("Press enter to start the game...");
Console.ReadLine();
iCount = 1;
}
else
{
Console.WriteLine("Just take your time and try to do it.");
}

}

while (QCount < 10)
{
int RandNum1 = numberGenerator.Next(1, 11);
int RandNum2 = numberGenerator.Next(1, 11);
Console.WriteLine("" + RandNum1 + " * " + RandNum2 + "");
Console.WriteLine();
int Input = Convert.ToInt32(Console.ReadLine());
int Answer = RandNum1 * RandNum2;

if (Input < 1 || Input > 100)
{
Console.WriteLine("The answer should be greater than 1 and less than 100.");
Console.ReadLine();
QCount--;
}
else
{

if (Input == Answer)
{
Console.WriteLine("Correct");
Console.WriteLine();
Console.WriteLine();
PCount++;
iScore++;
}
else
{
Console.WriteLine("The answer is " + Answer + ".");
Console.WriteLine();
Console.WriteLine();
}
}
QCount++;

}

Console.WriteLine("Finished. You scored " + iScore + "/10.");

}
}
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top