Question generate a score - array?

Scott

New member
Joined
Dec 10, 2017
Messages
1
Programming Experience
Beginner
Hello,
I am a beginner in coding in C# and really to coding in general. I am creating a quiz program and am having a problem getting it to generate a score. I am pretty sure I need to use and array but I do not understand where to place it and how to get the rest of the program to feed into it. Below is an example of my program. Any help would be greatly appreciated.
    public class Program
    {
        public static void Questionone()
        {
            Start:
            Console.Write("Q1: The Wright Brothers made their first flight at Kittyhawk North Carolina\n 1) True   2) False\n");
            int answer1 = Convert.ToInt32(Console.ReadLine());
            Console.ReadKey();
            if (answer1 < 1 || answer1 > 2)
            {
                Console.WriteLine("This was not one of the choices");
                goto Start;
            }
            else
            {
                String message1 = (answer1 != 1) ? "Incorrect" : "Correct";
                Console.WriteLine(message1);
                Console.WriteLine();
            }
        }
        public static void Questiontwo()
        {
            Start:
            Console.Write("Q2: What feat is Chuck Yeager most famous for?\n 1) Being a Pilot   2) Being a WWII Ace   3) Breaking the sound barrier   4) Being the first man in space\n");
            int answer2 = Convert.ToInt32(Console.ReadLine());
            Console.ReadKey();
            if (answer2 < 1 || answer2 > 4)
            {
                Console.WriteLine("This was not one of the Choices");
                goto Start;
            }
            else
            {
                String message2 = (answer2 != 3) ? "Incorrect" : "Correct";
                Console.WriteLine(message2);
                Console.WriteLine();
            }
        }
        public static void Questionthree()
        {
 
Firstly, I have added code formatting tags to your post. Hopefully you can see that it's far more readable. Please do so for us in future, like so:

[xcode=c#]your code here[/xcode]

If you want to add extra formatting, e.g. bold or colour to emphasise a particular line, then do this:

[code]your code here[/code]

Secondly, please be sensible when posting code. Post all of what's relevant and none of what's not, as best as you can determine. You've cut off your code part way through a method. If that method is relevant then where's the rest? If it's not relevant, why is it included at all? The more specific you are with what you post, the easier it is for us to help and the more likely you are to get the help you need.

As for the issue, why do you think you need to use an array? What purpose do you think that that will serve in your application? If we know what you're trying to achieve with it then we can help you achieve that.

That said, you should do a bit of reading on scope or variables and the like. In short, scope refers to the fact that a variable is only accessible in the block in which it is declared and only exists as long as that block is in memory. If you declare a variable inside a method then that variable is only accessible inside that method and ceases to exist when the method returns. If you call the method again, the variable is created again with no memory of it's value last time. If you want a variable's value to persist between method calls then the variable itself must exist between method calls, which means declaring it outside any method. Such a variable is referred to as a member variable or field, where a variable declared inside a method or a more specific block even is a local variable.
 

Latest posts

Back
Top Bottom