Question

In: Computer Science

So pretty much I need my code without the arrays, or lists. Please and thank you!...

So pretty much I need my code without the arrays, or lists. Please and thank you!

Important: You may not use arrays, lists, or similar for your questions. This will be covered in the next module. The objective is to use conditionals in order to achieve the overall task.

Checkpoint 3 is a continuation of the “Quiz” Programming Project.

This module week, you will implement repetitive tasks in your program while using conditional and iteration statements in C#.

  • Implement a loop option that suits your project. The goal is to cycle through all questions in a first round and read the appropriate user’s input from the console.
  • Mark whether the input is the correct answer.
  • Cycle through all incorrectly answered questions in a second round.
  • Tally the results and display the number of correct/incorrect answered questions, at the end.
  • Test the code for different input values of the variable(s) including out-of-range values and adding a statement displaying an error message.
  • Document a successful run of the program.

Important: You may not use arrays, lists, or similar for your questions. This will be covered in the next module. The objective is to use conditionals in order to achieve the overall task.

My CODE:

using System.IO;
using System;

namespace Checkpoint_3
{
class Program
{
static void Main(string[] args)
{
// display the current date

DateTime d = DateTime.Now;

Console.WriteLine("{0:MM/dd/yyyy HH:mm:ss}", d);
Console.WriteLine("Quiz");
Console.WriteLine("John Doe");
Console.WriteLine("ENGR 115");

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

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

//Method that returns questions
string getQuestions(int i)
{
string[] questions =
{
"Question 1 - ",
"Question 2 - ",
"Question 3 - ",
"Question 4 - ",
"Question 5 - ",
"Question 6 - ",
"Question 7 - ",
"Question 8 - ",
"Question 9 - ",
"Question 10 -"
}; //Questions for test

return questions[i];
}

//Method that returns answers
string getAnswers(int i)
{
string[] answers =
{
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. 5 \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
"A. \nB. \nC. \nD. ",
}; // Answer Bank

return answers[i];
}

//Method that returns correct answers
string getCorrectAnswers(int i)
{
string[] correctanswer =
{
"D", "D", "B", "B", "D", "D", "C", "B", "C", "A"
}; //These are the correct answers for the quiz. If one of these is incorrect it will re-display it a second time.

return correctanswer[i];
}

//Validates the input
Boolean validateInput(string answer, string correctAnswer)
{

  
{
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, or D. \n");
return false;
}
}
}

//Game
int playGame()
{
//Variables
int scoreCard = 0; // This is what I used to display the number of correct/incorrect answers during the second attempt.

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("{0}", getQuestions(i));
System.Console.WriteLine("{0}", getAnswers(i));
System.Console.WriteLine("Enter the 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("{0}", getQuestions(k));
System.Console.WriteLine("{0}", getAnswers(k));
System.Console.WriteLine("Enter the 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;
}

}

}

Solutions

Expert Solution

Screenshot

Program

using System;
namespace Checkpoint_3
{
    class Program
    {
        static void Main(string[] args)
        {
            // display the current date
            DateTime d = DateTime.Now;
            Console.WriteLine("{0:MM/dd/yyyy HH:mm:ss}", d);
            Console.WriteLine("Quiz");
            Console.WriteLine("John Doe");
            Console.WriteLine("ENGR 115");
            //Creating object
            Program p = new Program();
            Console.WriteLine("Score is {0}", p.playGame());
            Console.ReadKey();
        }
        //Method that returns questions
        string getQuestions(int i)
        {
            String question1 = "Question 1 - ";
            String question2 = "Question 2 - ";
            String question3 = "Question 3 - ";
            String question4 = "Question 4 - ";
            String question5 = "Question 5 - ";
            String question6 = "Question 6 - ";
            String question7 = "Question 7 - ";
            String question8 = "Question 8 - ";
            String question9 = "Question 9 - ";
            String question10 = "Question 10 - ";
            if (i == 1)
            {
                return question1;
            }
            else if (i == 2)
            {
                return question2;
            }
            else if (i == 3)
            {
                return question3;
            }
            else if (i == 4)
            {
                return question4;
            }
            else if (i == 5)
            {
                return question5;
            }
            else if (i == 6)
            {
                return question6;
            }
            else if (i == 7)
            {
                return question7;
            }
            else if (i == 8)
            {
                return question8;
            }
            else if (i == 9)
            {
                return question9;
            }
            else
            {
                return question10;
            }
        }
        //Method that returns answers
        string getAnswers(int i)
        {
            string answers1 = "A. \nB. \nC. \nD. ";
            string answers2= "A. \nB. \nC. \nD. ";
            string answers3 = "A. \nB. \nC. \nD. ";
            string answers4 = "A. \nB. \nC. \nD. ";
            string answers5 = "A. \nB. \nC. \nD. ";
            string answers6 = "A. \nB. \nC. \nD. ";
            string answers7 = "A. \nB. \nC. \nD. ";
            string answers8 = "A. \nB. \nC. \nD. ";
            string answers9 = "A. \nB. \nC. \nD. ";
            string answers10 = "A. \nB. \nC. \nD. ";
            if (i == 1)
            {
                return answers1;
            }
            else if (i == 2)
            {
                return answers2;
            }
            else if (i == 3)
            {
                return answers3;
            }
            else if (i == 4)
            {
                return answers4;
            }
            else if (i == 5)
            {
                return answers5;
            }
            else if (i == 6)
            {
                return answers6;
            }
            else if (i == 7)
            {
                return answers7;
            }
            else if (i == 8)
            {
                return answers8;
            }
            else if (i == 9)
            {
                return answers9;
            }
            else
            {
                return answers10;
            }
        }
        //Method that returns correct answers
        string getCorrectAnswers(int i)
        {
            string correctanswer1 = "D";
            string correctanswer2= "D";
            string correctanswer3 = "B";
            string correctanswer4 = "B";
            string correctanswer5 = "D";
            string correctanswer6 = "D";
            string correctanswer7 = "C";
            string correctanswer8 = "B";
            string correctanswer9 = "C";
            string correctanswer10 = "A";
            if (i == 1)
            {
                return correctanswer1;
            }
            else if (i == 2)
            {
                return correctanswer2;
            }
            else if (i == 3)
            {
                return correctanswer3;
            }
            else if (i == 4)
            {
                return correctanswer4;
            }
            else if (i == 5)
            {
                return correctanswer5;
            }
            else if (i == 6)
            {
                return correctanswer6;
            }
            else if (i == 7)
            {
                return correctanswer7;
            }
            else if (i == 8)
            {
                return correctanswer8;
            }
            else if (i == 9)
            {
                return correctanswer9;
            }
            else
            {
                return correctanswer10;
            }
        }
        //Validates the input
        Boolean validateInput(string answer, string correctAnswer)
        {
                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, or D. \n");
                    return false;
                }
        }
        //Game
        int playGame()
        {
            //Variables
            int scoreCard = 0; // This is what I used to display the number of correct/incorrect answers during the second attempt.

            bool questionsIncorrect1 = false;
            bool questionsIncorrect2 = false;
            bool questionsIncorrect3 = false;
            bool questionsIncorrect4 = false;
            bool questionsIncorrect5 = false;
            bool questionsIncorrect6 = false;
            bool questionsIncorrect7 = false;
            bool questionsIncorrect8 = false;
            bool questionsIncorrect9 = false;
            bool questionsIncorrect10 = false;

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

            Console.WriteLine("Attempt No 1");
            for (int i = 1; i <= 10; i++)
            {
                System.Console.WriteLine("{0}", getQuestions(i));
                System.Console.WriteLine("{0}", getAnswers(i));
                System.Console.WriteLine("Enter the 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++;
                    if (i == 1)
                    {
                        questionsIncorrect1=true;
                    }
                    else if (i == 2)
                    {
                        questionsIncorrect2 = true;
                    }
                    else if (i == 3)
                    {
                        questionsIncorrect3 = true;
                    }
                    else if (i == 4)
                    {
                        questionsIncorrect4 = true;
                    }
                    else if (i == 5)
                    {
                        questionsIncorrect5 = true;
                    }
                    else if (i == 6)
                    {
                        questionsIncorrect6 = true;
                    }
                    else if (i == 7)
                    {
                        questionsIncorrect7 = true;
                    }
                    else if (i == 8)
                    {
                        questionsIncorrect8 = true;
                    }
                    else if (i == 9)
                    {
                        questionsIncorrect9 = true;
                    }
                    else
                    {
                        questionsIncorrect10 = true;
                    }
                }
            }
            int k=0;
            while(j > -1)
            {
                Console.WriteLine("Attempt No 2");
              // for (int i = 1; i <= j+1; i++)
                //{
                    if (questionsIncorrect1)
                    {
                        k = 1;
                        questionsIncorrect1 = false;
                    }
                    else if (questionsIncorrect2)
                    {
                        k = 2;
                        questionsIncorrect2= false;
                    }
                    else if (questionsIncorrect3)
                    {
                        k = 3;
                        questionsIncorrect3 = false;
                    }
                    else if (questionsIncorrect4)
                    {
                        k = 4;
                        questionsIncorrect4 = false;
                    }
                    else if (questionsIncorrect5)
                    {
                        k = 5;
                        questionsIncorrect5 = false;
                    }
                    else if (questionsIncorrect6)
                    {
                        k = 6;
                        questionsIncorrect6 = false;
                    }
                    else if (questionsIncorrect7)
                    {
                        k = 7;
                        questionsIncorrect7 = false;
                    }
                    else if (questionsIncorrect8)
                    {
                        k = 8;
                        questionsIncorrect8 = false;
                    }
                    else if (questionsIncorrect9)
                    {
                        k = 9;
                        questionsIncorrect9 = false;
                    }
                    else if(questionsIncorrect10)
                    {
                        k = 10;
                        questionsIncorrect10 = false;
                    }
                    System.Console.WriteLine("{0}", getQuestions(k));
                    System.Console.WriteLine("{0}", getAnswers(k));
                    System.Console.WriteLine("Enter the 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));
                    }
                j--;
                //}
            }

            return scoreCard;
        }

--------------------------------------------------------------------------------

Output

09-08-2019 19:16:12
Quiz
John Doe
ENGR 115

Attempt No 1
Question 1 -
A.
B.
C.
D.
Enter the answer ::
D

Question 2 -
A.
B.
C.
D.
Enter the answer ::
D

Question 3 -
A.
B.
C.
D.
Enter the answer ::
C

Question 4 -
A.
B.
C.
D.
Enter the answer ::
A

Question 5 -
A.
B.
C.
D.
Enter the answer ::
B

Question 6 -
A.
B.
C.
D.
Enter the answer ::
C

Question 7 -
A.
B.
C.
D.
Enter the answer ::
D

Question 8 -
A.
B.
C.
D.
Enter the answer ::
D

Question 9 -
A.
B.
C.
D.
Enter the answer ::
C

Question 10 -
A.
B.
C.
D.
Enter the answer ::
D

Attempt No 2
Question 3 -
A.
B.
C.
D.
Enter the answer ::
C

Correct Answer is B
Attempt No 2
Question 4 -
A.
B.
C.
D.
Enter the answer ::
A

Correct Answer is B
Attempt No 2
Question 5 -
A.
B.
C.
D.
Enter the answer ::
A

Correct Answer is D
Attempt No 2
Question 6 -
A.
B.
C.
D.
Enter the answer ::
D

Attempt No 2
Question 7 -
A.
B.
C.
D.
Enter the answer ::
C

Attempt No 2
Question 8 -
A.
B.
C.
D.
Enter the answer ::
D

Correct Answer is B
Attempt No 2
Question 10 -
A.
B.
C.
D.
Enter the answer ::
C

Correct Answer is A
Score is 5

---------------------------------------------------------

Note:-

I assume you want to avoid all arrays and change into conditional statements.Any queries let me know


Related Solutions

HI please answer all parts of my question. Thank you so much! I will rate you!...
HI please answer all parts of my question. Thank you so much! I will rate you! Why do we call cardiac muscle to be a syncytium of many individual muscle cells? What is the name of membranes that connect longitudinally adjacent muscle cells? As you know the mechanism of organophosphates involves irreversible inhibitors of AChE. Organophosphates have been used in several murders (VX used to kill the half-brother of North Korean dictator Kim Jong Un; Sarin gas used to kill...
I need a scholarship essay for my nursing program. please and thank you.
I need a scholarship essay for my nursing program. please and thank you.
In Java please. I put down my code and what I was able to achieve so...
In Java please. I put down my code and what I was able to achieve so far: public class Animal {   private String gender; //stores the gender of the animal    private String type; //stores the type of the animal(bear of fish)    private int strength; //stores the strength of the animal    public Animal() {        gender = "none";        type = "none";        strength = 0;    }        public Animal (String g, String...
Please comment on my answer, what do you think? I need insight, thank you! Q: Answer...
Please comment on my answer, what do you think? I need insight, thank you! Q: Answer both questions below about the EOQ model. (a) In the EOQ model, unit product cost or selling price, C, is not included in the formula we use to solve for the economic order quantity. Explain why it is not necessary to include this information in the EOQ formula. (b) What are the major limitations of the EOQ model? A: A). In the EOQ model,...
Audit and Investigation- Please assist me in answering this in essayform please. Thank you so much...
Audit and Investigation- Please assist me in answering this in essayform please. Thank you so much As part of the planning an audit and designing an audit approach one major part of the planning is to understand the client’s business and industry. Select a specific business example and provide a bullet point analysis of what would be of interest in the understanding of that client business and industry and its impact on the audit
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1)...
Hey! I'm having trouble answering this for my assignment. Thank you so much in advance. 1) Which type of vessels, arteries or veins, has more muscle fibers? What is the functional significance of this? 2a) In general, we have no conscious control over smooth muscle or cardiac muscle function, whereas we can consciously control to some extent all skeletal muscles. Can you consciously control your breathing? What does this tell you about the muscle type of the diaphragm? 2b) What...
I need the answer explained and computer typer so I can read it! thank you For...
I need the answer explained and computer typer so I can read it! thank you For a simple linear regression model yi= α + βxi + ui , i = 1 1- Suppose researchers want to know the effect of elementary school class size on students’ math scores(total score is 100), intuitively they think there exists a negative linear relationship between class size and students’ math scores. The researchers want to know the marginal effect of class size on student’s...
FIND THE ANSWER WITH EXCEL PLEASE! THANK YOU SO MUCH! (2) The lifetime of a computer...
FIND THE ANSWER WITH EXCEL PLEASE! THANK YOU SO MUCH! (2) The lifetime of a computer circuit has an exponential distribution with mean of three years. Find the probability that a circuit lasts longer than 4 years.
PLEASE COMPUTE THE FOLLOWING IN EXCEL and show the excel sheet, Thank you so much! The...
PLEASE COMPUTE THE FOLLOWING IN EXCEL and show the excel sheet, Thank you so much! The following are the runs scored totals for 9 players for the 2016 New York Yankees: 56,43,63,68,58,80,71,32,19 (a) Find the mean and median (b) Find the standard deviation of this population (c) Considering this as a normal sample of American League players for the 2016 season, find a 99% Confidence Interval for the actual mean of Runs Scored for AL players, 2016 . (d) Considering...
Please Read This Article and answer the questions that follow: Thank You so much for taking...
Please Read This Article and answer the questions that follow: Thank You so much for taking the time to do this I will rate well!! In many cities, finding an available parking spot on the street seems about as likely as winning the lottery. But iflocal governments relied more on the price system, they might be able to achieve a more efficient allocation of this scarce resource. A Meter So Expensive, It Creates Parking Spots By Michael Cooper and Jo...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT