AnswerBun.com

Decluttering quiz game

I’ve been learning C# for 2 month and in the process of writing a quiz via file i/o. I want to know if there is a better way to getting the questions and answers rather than using switch statement so that it does not look too cluttered. I’ve tried using fields and properties but I don’t know how to implement them into getting the lines in the txt. I’ve been using switch statement to get the array of the lines and the program work.

Here is a simple of my program:

    public class QuestionUI
    {
       
        String[] fileName = File.ReadAllLines(@"TraviaQuestion.txt");
        private String [] NO_OF_ANSWERS = new string[5];
        private String[] NO_OF_QUESTIONS = new String[5];

 public void Questions(int num)
        {
            NO_OF_QUESTIONS[0] = fileName[0];
   
            switch(num)
            {
                case 1:
                    {
                        Console.WriteLine("n" + NO_OF_QUESTIONS[0]);
                        GetAnswer(1);
                        break;
                    }
               }
         }

  public void GetAnswer(int num)
        {
            switch (num)
            {
                case 1:
                    {
                        Console.WriteLine(NO_OF_ANSWERS[0] = fileName[1]);
                        Console.WriteLine(NO_OF_ANSWERS[0] = fileName[2]);
                        break;
                    }
            }
         }

 public void GetCorrectAnswer(String input, int num)
        {
            
            switch (num)
            {
                case 1:
                    {
                        if (input.ToUpper() != "B")
                        {
                            Console.WriteLine("Incorrect!");
                            GetExplanation(1);
                        }
                        else
                        {
                            Console.WriteLine("Correct!");
                        }
                        break;
                    }
             }
           }
 public void GetExplanation(int num)
        {
           switch(num)
            {
                case 1:
                    {
                        Console.WriteLine(fileName[6]);
                        break;
                    }
            }
         }
 public void ReadQuestionFile()
        {
            String input;

            Questions(1);
           input = Console.ReadLine();
            GetCorrectAnswer(input,1);
        }

```

Code Review Asked by Kue on December 29, 2020

0 Answers

Add your own answers!

Related Questions

C++ linked list inheriting from node class

1  Asked on November 17, 2021 by devinthenrough

       

MMMRjs a product of BYTES Genesis

3  Asked on November 17, 2021 by syed-mohammad-sannan

         

Simple marker rendering

1  Asked on November 17, 2021

     

C++20 ScopeGuard

1  Asked on November 15, 2021

   

LeetCode 37: Sudoku Solver

1  Asked on November 13, 2021

         

Converting a float to a fraction as a string

1  Asked on November 11, 2021 by stonkilla4

   

C# consecutive and redundant null checks

6  Asked on November 11, 2021 by frederik-hoeft

   

Format string processing similar to date or printf()

2  Asked on November 11, 2021 by domsson

     

Improvement to Luhn-Checksum Algorithm in Java

2  Asked on November 11, 2021 by elauser

   

Full Adder in Verilog

1  Asked on November 8, 2021

 

Python palindrome checker function

4  Asked on November 8, 2021 by dicomp

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.