Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How can I put it in an array and display each question one by one (I'm quite new in this area)

CrissssCrissss Member
edited December 2020 in Programming

string Answer = "";

          string Option = "";

          int score = 0;

          int Tries = 0;


          do

          {

            score = 0;

            //Give the Instructions of this Quiz

            Console.WriteLine("Multiple choice questions, select one answer in each question. Make sure your choice either A, B, C or D. (Note: You have 2 attempts, ATTEMPT:" + (Tries + 1));

            // Display Question 1

            Console.WriteLine("Question 1.) +2+2");

            //Display all the Posible Choices

            Console.WriteLine("A. 1");

            Console.WriteLine("B. 2");

            Console.WriteLine("C. 3");

            Console.WriteLine("D. 4");


            Console.WriteLine("Answer:");

            Answer = Console.ReadLine().ToUpper(); //Read the Answer and Convert it to Upper Case


            switch (Answer)

            {


              case "A":

                break;

              case "B":

                break;

              case "C":

                score = score + 1; // Add +1 to the score if the Answer is correct

                break;

              case "D":

                break;

              default:

                Console.WriteLine("You are wrong");

                break;

            }

            //Display Question 2

            Console.WriteLine("Question 2.) How many Fingers do you have in your hands");

            //Display all the Posible Choices

            Console.WriteLine("A. 10");

            Console.WriteLine("B. 15");

            Console.WriteLine("C. 20");

            Console.WriteLine("D. 5");


            Console.WriteLine("Answer:");

            Answer = Console.ReadLine().ToUpper(); //Read the Answer and Convert it to Upper Case


            switch (Answer)

            {


              case "A":

                score = score + 1; // Add +1 to the score if the Answer is correct

                break;


              case "B":

                break;

              case "C":

                break;

              case "D":

                break;

              default:

                Console.WriteLine("Nope");

                break;

            }

            //Display Question 3

            Console.WriteLine("Question 3.) what do you need to survive?");

            //Display all the Posible Choices

            Console.WriteLine("A. House");

            Console.WriteLine("B. Water");

            Console.WriteLine("C. Chocolate");

            Console.WriteLine("D. Fruits");


            Console.WriteLine("Answer:");

            Answer = Console.ReadLine().ToUpper(); //Read the Answer and Convert it to Upper Case


            switch (Answer)

            {


              case "A":

                break;


              case "B":

                score = score + 1; // Add +1 to the score if the Answer is correct

                break;

              case "C":

                break;

              case "D":

                break;

              default:

                Console.WriteLine("You are wrong");

                break;

            }

                   Console.WriteLine("Your score is" + (score / 3* 100) + "%");

            Tries++; //Increment the No of Tries

            Console.WriteLine("\nWould you like to try one more time? (Y/N):");

            Option = Console.ReadLine().ToUpper();

            if (Option != "Y")

              break;


          } while (Option != "N" && Tries <= 1);


        }

      }

Best Answer

  • HNJHNJ Member
    Accepted Answer

    But I would recommend creating a Question class, so that each question will have its own answer, score etc. Tell me if you have interest in this.

Answers

  • I will not go into your quiz but in what you need:


    string[] Questions; //your Questions array
    
    foreach(string question in Questions)
    {
         //The foreach loop for repeat/loop over each element of Questions
        // the "question" variable is the question in each loop
        //ask your question
        //Take input and check answer for each
    }
    
Sign In or Register to comment.