2
\$\begingroup\$

I wanted to get some feedback concerning the program. It's console based and in C#. If I should try to add constraints like making sure only the 4 questions shown are able to be typed in and nothing else or uses a number system to retrieve and set answers and if to add a randomization. If I am to add randomization how am I to do so with string and methods? Was thinking of loading it from an external file where questions and answers would be read, randomized and printed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Trivia_Game
{
class Questions
{
    public void Question1()
    {
        List<string> Q1 = new List<string>();
        Q1.Add("Paris");
        Q1.Add("Spain");
        Q1.Add("England");
        Q1.Add("Portugal");

        string Answer1="";

        string TrueAnswer = "Paris";

            for (int i = 0; i < Q1.Count; i++)
            {

                Console.Write(Q1[i] + ", ");

            }

            Console.WriteLine();

        while (Answer1 != TrueAnswer)
        {
            Console.WriteLine("What is the Capital of France?");
            Answer1 = Console.ReadLine();
            Console.WriteLine();

            if (Answer1 != TrueAnswer)
            {
                Console.WriteLine("Wrong answer");
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("Correct");
            }
        }
    }
}
class Program
{
    static void Main(string[] args)
    {
        Questions questions = new Questions();

        questions.Question1();

        Console.ReadKey();
    }
}
}
\$\endgroup\$
1
\$\begingroup\$

You can create a Question class which include the question, the answers, and the right answer.

Then you create a list of questions hard coded / from file / from server ( what ever you want)

Convert the code in Question 1 to be more generic and work with the Question class.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you, I will do just that. \$\endgroup\$ Apr 11 '20 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.