Help me fully explain this code please.

Discussion in 'C Programming' started by triada17, Jan 14, 2020.

  1. triada17

    triada17

    Joined:
    Jan 14, 2020
    Messages:
    1
    Likes Received:
    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.");

    }
    }
    }
     
    triada17, Jan 14, 2020
    #1
    1. Advertisements

  2. triada17

    John Joe

    Joined:
    Apr 25, 2017
    Messages:
    131
    Likes Received:
    15
    Location:
    Malaysia
    Wonder where you get this code?
     
    John Joe, Jan 16, 2020 at 3:35 AM
    #2
    1. 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 (here). After that, you can post your question and our members will help you out.