Tech Support Forum banner
Status
Not open for further replies.
1 - 8 of 8 Posts

·
Registered
Joined
·
64 Posts
Discussion Starter · #1 ·
Hey guys, I'm wanting to make a basic 10 question quiz using c# in a console application, it will be multiple choice and at the end add up all the users marks out of ten, i have all the questions and the basic code for it but am struggling with the code to add up the marks, any help with this would be greatly appreciated.

Thanks

Matt
 

·
God (TSF Enthusiast)
Joined
·
1,118 Posts
Here's some pseudo code for you, I hope it helps:

Keep in mind I'm not so great at C# so this probably won't work for you, but you could easily adapt it. Basically I'm comparing the values of two arrays, if they match I'm adding 1 to count, if not, I'm setting count equal to whatever count is--though you could just as well do nothing.

for (x in answer){
if (answer[x]=correct[x]){count++}
else{count=count}
}
 

·
God (TSF Enthusiast)
Joined
·
1,118 Posts
Post some code :)

We'll help you debug/improve it.
 

·
Registered
Joined
·
64 Posts
Discussion Starter · #5 ·
Bellow is what i have so far, I imagine that ive gone the long way around doing it, i need something in there to add up the scores as it goes and then display them at the end of the program. and perhaps even something along the lines of the user entering his name and maybe being added to a score board.

Thanks

Code:
using System
;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace quiz
{
    class Program
    {
        static void Main(string[] args)
        {
            // Menu................................................................................................................................
            int iChoice;
            int iInput1;


            Console.WriteLine("The Ultimate pub quiz");
            Console.WriteLine();
            Console.WriteLine("Welcome to the Ultimate Pub Quiz, you will be asked 10 general knoledge");
            Console.WriteLine("multiple choice questions, play alone or compare your score with a friend");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("To start the pub quiz please press 1");

            iChoice = Convert.ToInt32(Console.ReadLine());

            while (iChoice < 1 || iChoice > 1)
            {
                Console.WriteLine();
                Console.WriteLine("To start the pub quiz please press 1");
                iChoice = Convert.ToInt32(Console.ReadLine());
            }

            {

                if (iChoice == 1)
                    Console.WriteLine();
                //2 ...............................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine();
                Console.WriteLine("Question 1");
                Console.WriteLine();
                Console.WriteLine("How many pairs of ribs does the normal human have?");
                Console.WriteLine();
                Console.WriteLine("Option 1: 11");
                Console.WriteLine("Option 2: 12");
                Console.WriteLine("Option 3: 13");
                Console.WriteLine("Option 4: 14");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 2)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }
               

                //A ..........................................................................................................................
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();


                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 2");
                Console.WriteLine();
                Console.WriteLine("Who wrote the classic novel ‘Les Miserables’?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Victor Hugo");
                Console.WriteLine("Option 2: William Shakespear");
                Console.WriteLine("Option 3: Daniel Lewis");
                Console.WriteLine("Option 4: Emily Bronty");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 1)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }


                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //A...............................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 3");
                Console.WriteLine();
                Console.WriteLine("What was the name of Sherlock Holmes Housekeeper?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Mrs Hudson");
                Console.WriteLine("Option 2: Mr Watson");
                Console.WriteLine("Option 3: Mr Hudson");
                Console.WriteLine("Option 4: Mrs Hudson");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");


                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Answer: (1-4)");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 1)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //D..............................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 4");
                Console.WriteLine();
                Console.WriteLine("Which actress played the part of Sybil Fawlty in Television’s Fawlty Towers?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Prunella Scales");
                Console.WriteLine("Option 2: Prudella Scale");
                Console.WriteLine("Option 3: Prundella Scale");
                Console.WriteLine("Option 4: Prunella Scale");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 4)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }


                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();


                //C.................................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 5");
                Console.WriteLine();
                Console.WriteLine("What was the title of Beethoven’s only opera?");
                Console.WriteLine();
                Console.WriteLine("Option 1:Tale of two towers");
                Console.WriteLine("Option 2:Figero");
                Console.WriteLine("Option 3:Fidelio");
                Console.WriteLine("Option 4:The third");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 3)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //A......................................................................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 6");
                Console.WriteLine();
                Console.WriteLine("Which river flows through the city of Dublin?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Liffey");
                Console.WriteLine("Option 2: Nile");
                Console.WriteLine("Option 3: Trent");
                Console.WriteLine("Option 4: Seven");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 1)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }


                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //A...............................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 7");
                Console.WriteLine();
                Console.WriteLine("Who appeared with David McCallum in the TV series ‘Sapphire and Steel");
                Console.WriteLine();
                Console.WriteLine("Option 1: Joanna Lumley");
                Console.WriteLine("Option 2: Dawn French");
                Console.WriteLine("Option 3: Peter Kay");
                Console.WriteLine("Option 4: Angus Deaton");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 1)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //C	.................................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 8");
                Console.WriteLine();
                Console.WriteLine("Which Irishman won the Tour de France in 1987?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Danny Wells");
                Console.WriteLine("Option 2: Paddy Murphy");
                Console.WriteLine("Option 3: Stephen Roche");
                Console.WriteLine("Option 4: Seamus Mc'fadden");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 3)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }


                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //D.................................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 9");
                Console.WriteLine();
                Console.WriteLine("In which European country is Cro-Magnon, famous for the discovery of four Palaeolithic skeletons in 1868?");
                Console.WriteLine();
                Console.WriteLine("Option 1: England");
                Console.WriteLine("Option 2: Germany");
                Console.WriteLine("Option 3: Italy");
                Console.WriteLine("Option 4: France");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 4)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                //2...............................................................................................................................
                Console.WriteLine("________________________________________________________________________________");
                Console.WriteLine("Question 10");
                Console.WriteLine();
                Console.WriteLine("How was Achilles killed?");
                Console.WriteLine();
                Console.WriteLine("Option 1: Bad Heel");
                Console.WriteLine("Option 2: Arrow in his head");
                Console.WriteLine("Option 3: Arrow through the heart");
                Console.WriteLine("Option 4: Bungee Jump accident");
                Console.WriteLine();
                Console.WriteLine("Answer: (1-4)");

                iInput1 = Convert.ToInt32(Console.ReadLine());

                while (iInput1 < 1 || iInput1 > 4)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an answer between 1 and 4");
                    iInput1 = Convert.ToInt32(Console.ReadLine());
                }
                if (iInput1 == 2)
                {

                    Console.WriteLine();
                    Console.WriteLine("Correct");
                }
                else
                {
                    Console.WriteLine("Sorry, Wrong answer");
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(); 
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Thanks for playing");
                Console.WriteLine();
                Console.WriteLine("Will display the final score here and the percentage.");






































                Console.WriteLine("Press any key to exit");
                Console.ReadKey();






            }
        }
    }
}
 

·
Registered
Joined
·
105 Posts
just declare another variable and increment if correct, and reset it afterwards.

// Menu................................................................................................................................
int iChoice;
int iInput1;
int iCorrect;
if (iInput1 == 2)
{

Console.WriteLine();
Console.WriteLine("Correct");
iCorrect++;
}
else
{
Console.WriteLine("Sorry, Wrong answer");
}
Console.WriteLine("Thanks for playing");
Console.WriteLine();
Console.WriteLine("Will display the final score here and the percentage.");
Console.WriteLine("You got " + iCorrect + " questions right!");
 
1 - 8 of 8 Posts
Status
Not open for further replies.
Top