Question

So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make to the code. If it works I will promptly thumbs up! Please help!

Here is my code so far:

using System;

namespace Checkpoint_2
{
class Program
{
//Method that returns questions
string getQuestions(int i)
{
string[] questions =
{
"1. Which mathematician's principle of fluid dynamics is the most widely taught explanation of how planes fly?",
"2. Movement of the plane about the vertical axis of motion is called?",
"3. When the pilot moves the wheel on the control/yoke to the left the result will be?",
"4. VOR stands for Variable Oscillation Radar.",
"5. Where on the aircraft would you find the green navigation light?",
"6. In aviation, ILS stands for Instrument Landing System.",
"7. What is the purpose of an aircraft’s altimeter?",
"8. The four main forces acting on an air plane are: lift, drag, thrust and weight.",
"9. VFR stands for Vehicle Flight Recorder.",
"10. In aviation, what is FOD?"
}; // will be questions used on test. 6 Multiple choice and 4 true/false

return questions[i];
}

//Method that returns answers
string getAnswers(int i)
{
string[] answers =
{
"a. Albert Einstein b. Plato c. Bill Smith d. Daniel Bernoulli",
"a. Bank b. Yaw c. Pitch d. Flight",
"a. The elevator goes up b. The right aileron goes up and the left aileron goes down c. The left aileron goes up and the right aileron goes down d. Both ailerons go down",
"true false",
"a. Left Wingtip b. Above the Cockpit c. Right Wingtip d. Tail",
"true false",
"a. To show the aircraft’s airspeed b. To show the aircraft’s angle of attack c. To show the aircraft’s engine temperature d. To show the aircraft’s altitude",
"true false",
"true false",
"a. Fire Oppression Device b. Foreign Object Debris c. Foul Odor Detector d. First Officer’s Den",
}; // these will stand as answer bank for all questions

return answers[i];
}

//Method that returns correct answers
string getCorrectAnswers(int i)
{
string[] correctanswer =
{
"d",
"b",
"c",
"false",
"c",
"true",
"d",
"true",
"false",
"b"
}; //these are the correct answers to all the question. any other selections will be counted as incorrect

return correctanswer[i];
}

//Validates the input
Boolean validateInput(string answer, string correctAnswer)
{
//For true/false questions
if (correctAnswer.Equals("true") || correctAnswer.Equals("false"))
{
if (answer.Equals("true") || answer.Equals("false"))
{
return true;
}
else
{
Console.WriteLine("\n Invalid Answer!!! Answer as either True/False... \n");
return false;
}
}
else
{
if (answer.Equals("a") || answer.Equals("b") || answer.Equals("c") || answer.Equals("d"))
{
return true;
}
else
{
Console.WriteLine("\n Invalid Answer!!! Answer as either a/b/c/d... \n");
return false;
}
}
}

//Game
int playGame()
{
//Variables
int scoreCard = 0; // everyone starts with 0 correct out of ten. once quiz is completed score will be listed as 1-10.

int[] questionsIncorrect = new int[10];

Console.WriteLine();
int j = -1;
string check;

Console.WriteLine("Attempt No 1");
for (int i = 0; i < 10; i++)
{
System.Console.WriteLine("Q{0}", getQuestions(i));
System.Console.WriteLine("{0}", getAnswers(i));
System.Console.WriteLine("Enter Answer :: ");
check = Console.ReadLine();

//Validating answer
while (validateInput(check, getCorrectAnswers(i)) == false)
{
//Re-reading
check = Console.ReadLine();
}

Console.WriteLine();
if (check.Equals(getCorrectAnswers(i)))
{
scoreCard = scoreCard + 1;
}
else
{
j++;

questionsIncorrect[j] = i;
}
}
int k;
if (j > -1)
{
Console.WriteLine("Attempt No 2");
for (int i = 0; i <= j; i++)
{
k = questionsIncorrect[i];
System.Console.WriteLine("Q{0}", getQuestions(k));
System.Console.WriteLine("{0}", getAnswers(k));
System.Console.WriteLine("Enter Answer :: ");
check = Console.ReadLine();

//Validating answer
while (validateInput(check, getCorrectAnswers(k)) == false)
{
//Re-reading
check = Console.ReadLine();
}

Console.WriteLine();
if (check.Equals(getCorrectAnswers(k)))
{
scoreCard = scoreCard + 1;
}
else
{
System.Console.WriteLine("Correct Answer is {0}", getCorrectAnswers(k));
}
}
}

return scoreCard;
}

//Main method
static void Main(string[] args)
{
Console.WriteLine("General Aviation Quiz");

//Welcome To Program
Console.WriteLine("James Fox, ENGR115- General Aviation Quiz");

//Creating object
Program p = new Program();

Console.WriteLine("Score is {0}", p.playGame());
Console.ReadKey();
}

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

namespace Checkpoint_2
{
    class Program
    {
        //Method that returns questions
        string getQuestions(int i)
        {
            string[] questions =
            {
"1. Which mathematician's principle of fluid dynamics is the most widely taught explanation of how planes fly?",
"2. Movement of the plane about the vertical axis of motion is called?",
"3. When the pilot moves the wheel on the control/yoke to the left the result will be?",
"4. VOR stands for Variable Oscillation Radar.",
"5. Where on the aircraft would you find the green navigation light?",
"6. In aviation, ILS stands for Instrument Landing System.",
"7. What is the purpose of an aircraft’s altimeter?",
"8. The four main forces acting on an air plane are: lift, drag, thrust and weight.",
"9. VFR stands for Vehicle Flight Recorder.",
"10. In aviation, what is FOD?"
}; // will be questions used on test. 6 Multiple choice and 4 true/false

            return questions[i];
        }

        //Method that returns answers
        string getAnswers(int i)
        {
            string[] answers =
            {
"a. Albert Einstein b. Plato c. Bill Smith d. Daniel Bernoulli",
"a. Bank b. Yaw c. Pitch d. Flight",
"a. The elevator goes up b. The right aileron goes up and the left aileron goes down c. The left aileron goes up and the right aileron goes down d. Both ailerons go down",
"true false",
"a. Left Wingtip b. Above the Cockpit c. Right Wingtip d. Tail",
"true false",
"a. To show the aircraft’s airspeed b. To show the aircraft’s angle of attack c. To show the aircraft’s engine temperature d. To show the aircraft’s altitude",
"true false",
"true false",
"a. Fire Oppression Device b. Foreign Object Debris c. Foul Odor Detector d. First Officer’s Den",
}; // these will stand as answer bank for all questions

            return answers[i];
        }

        //Method that returns correct answers
        string getCorrectAnswers(int i)
        {
            string[] correctanswer =
            {
                "d",
                "b",
                "c",
                "false",
                "c",
                "true",
                "d",
                "true",
                "false",
                "b"
            }; //these are the correct answers to all the question. any other selections will be counted as incorrect

            return correctanswer[i];
        }

        //Validates the input
        Boolean validateInput(string answer, string correctAnswer)
        {
            //For true/false questions
            if (correctAnswer.Equals("true") || correctAnswer.Equals("false"))
            {
                if (answer.Equals("true") || answer.Equals("false"))
                {
                    return true;
                }
                else
                {
                    Console.WriteLine("\n Invalid Answer!!! Answer as either True/False... \n");
                    return false;
                }
            }
            else
            {
                if (answer.Equals("a") || answer.Equals("b") || answer.Equals("c") || answer.Equals("d"))
                {
                    return true;
                }
                else
                {
                    Console.WriteLine("\n Invalid Answer!!! Answer as either a/b/c/d... \n");
                    return false;
                }
            }
        }

        //Game
        int playGame()
        {
            //Variables
            int scoreCard = 0; // everyone starts with 0 correct out of ten. once quiz is completed score will be listed as 1-10.

            int[] questionsIncorrect = new int[10];

            Console.WriteLine();
            int j = -1;
            string check;

            Console.WriteLine("Attempt No 1");
            for (int i = 0; i < 10; i++)
            {
                System.Console.WriteLine("Q{0}", getQuestions(i));
                System.Console.WriteLine("{0}", getAnswers(i));
                System.Console.WriteLine("Enter Answer :: ");
                check = Console.ReadLine();

                //Validating answer
                while (validateInput(check, getCorrectAnswers(i)) == false)
                {
                    //Re-reading
                    check = Console.ReadLine();
                }

                Console.WriteLine();
                if (check.Equals(getCorrectAnswers(i)))
                {
                    scoreCard = scoreCard + 1;
                }
                else
                {
                    j++;

                    questionsIncorrect[j] = i;
                }
                Console.Clear(); // TO CLEAR THE SCREEN
            }
            int k;
            if (j > -1)
            {
                Console.WriteLine("Attempt No 2 for wrong question");
                for (int i = 0; i <= j; i++)
                {
                    k = questionsIncorrect[i];
                    System.Console.WriteLine("Q{0}", getQuestions(k));
                    System.Console.WriteLine("{0}", getAnswers(k));
                    System.Console.WriteLine("Enter Answer :: ");
                    check = Console.ReadLine();

                    //Validating answer
                    while (validateInput(check, getCorrectAnswers(k)) == false)
                    {
                        //Re-reading
                        check = Console.ReadLine();
                    }

                    Console.WriteLine();
                    if (check.Equals(getCorrectAnswers(k)))
                    {
                        scoreCard = scoreCard + 1;
                        Console.Clear(); // TO CLEAR THE SCREEN
                    }
                    else
                    {
                        System.Console.WriteLine("Correct Answer is {0}\n\n", getCorrectAnswers(k));
                        Console.ReadLine(); // WAIT FOR KEY PRESS
                        Console.Clear(); // TO CLEAR THE SCREEN
                    }
                  
                }
             
            }

            return scoreCard;
        }

        //Main method
        static void Main(string[] args)
        {
            Console.WriteLine("General Aviation Quiz");

            //Welcome To Program
            Console.WriteLine("James Fox, ENGR115- General Aviation Quiz");

            //Creating object
            Program p = new Program();
            Console.WriteLine("Score is {0}", p.playGame());
            Console.ReadKey();
        }

    }

}

Console.clear(); is use to clear the screen...

Add a comment
Know the answer?
Add Answer to:
So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C#, I am getting error placing them all in one file pls set them in the...

    C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null;    }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...

  • [C#] I need to convert this if/else statements into Switch I have the code for the...

    [C#] I need to convert this if/else statements into Switch I have the code for the if/else but now need to turn it into a switch. The Console.WriteLine and all that is fine. I just need to convert the if/else.      int x1, x2, y1, y2;                 Console.WriteLine("What is smallest value of x:");                 x1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of x:");                 x2 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is smallest value of y:");                 y1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of y:");                 y2 =...

  • C# Sharp for Visual Studio Need Expert help -to use Video studio to write a Quiz....

    C# Sharp for Visual Studio Need Expert help -to use Video studio to write a Quiz. The quiz is multiple choice with 10 questions. I need a source code to start and I can copy and paste my questions. EX: using System; namespace Quiz     class MainClass     {         public static void Main(string[] args)         {         Console.WriteLine("Welcome to the Quiz!");             Console.WriteLine("");                 // Declare variables implicitly and explicitly             var Question 1= "How many trees in a forest?");                var Answer1a = "3"                    var Answer1b ="5"...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example,...

    (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example, if a user inputs a repeated number the program should regenerate or ask to enter again. If needed, here is the program requirements: Create a lottery game application. Generate four random numbers, each between 1 and 10. Allow the user to guess four numbers. Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess,...

  • I am writing a console application in C#. It is a receipt where the user inputs...

    I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • C #sharp Visual Studio Programming, Implement the array declaration and initialization for -For this quiz I...

    C #sharp Visual Studio Programming, Implement the array declaration and initialization for -For this quiz I attached (EXAMPLE of 10 questions).... Using arrays to format this quiz? using System; namespace Quiz {     class MainClass     {         public static void Main(string[] args)         {             Console.WriteLine("Welcome to the Quiz!");             Console.WriteLine("--------------------------------");             Console.WriteLine(" ");             //Questions                       var Question1 = "1. How many trees in a forest?";             var Question2 = "2. Sample Question";             var Question3 =...

  • I am trying to run this program in Visual Studio 2017. I keep getting this build...

    I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...

  • So I am working on an assignment where we make a rudimentary browser history with c#....

    So I am working on an assignment where we make a rudimentary browser history with c#. The requirement is that we need to use a linked list to do this. The issue that I am having is that when I want to go backwards in the history and print it takes from the beginning of the list and not the front. (Example is if I had a list with 1, 2, 3, 4 in it and went back It would...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT