Jump to content

C# help?

Go to solution Solved by cluelessgenius,

So usually im not a fan of just giving out answers because i dont want to rob you of the learning effect but i gotta go right now and since i dont know wether im gonna be on today later im gonna post one of many possible solutions - namely my own solution - to this task in a spoiler. feel free to use it but id rather you try and understand whats happening if this isnt as urgent then ill be back tommorrow and gladly help you understand as best i can

 

main()

Spoiler

static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("            Please pick an option between 1 and 5");
                Console.WriteLine("\n1.Tell me 10 names and i will say them back");
                Console.WriteLine("\n2.average of 5 numbers");
                Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
                Console.WriteLine("\n4.Welcomes you to the system");
                Console.WriteLine("\nQuit is 0");

                switch (Console.ReadKey().KeyChar)
                {
                    case '1':
                        Console.Clear();
                        NameRepeat();
                        break;
                    case '2':
                        Console.Clear();
                        AverageOfFive();
                        break;
                    case '3':
                        Console.Clear();
                        OddOrEven();
                        break;
                    case '4':
                        Console.Clear();
                        Welcome();
                        break;
                    case '0':
                        Console.Clear();
                        Quit();
                        break;
                }

                Console.WriteLine("\nPress any Key to continue...");
                Console.ReadKey();
            }
        }

 

 

NameRepeat()

Spoiler

private static void NameRepeat()
        {
            string[] array1 = new string[10];
            Console.WriteLine("please give me 10 names and i will repeat them to you");
            Console.WriteLine("Confirm each Name by hitting 'Enter'");

            for (int i = 0; i < array1.Length; i++)
            {
                array1[i] = Console.ReadLine();
            }
            for (int j = 0; j < array1.Length; j++)
            {
                Console.WriteLine("User " + j + " is :" + array1[j]);
            }
        }

 

 

Welcome()

Spoiler

private static void Welcome()
        {
            Console.Write("Please enter your name: ");
            string myName = Console.ReadLine();
            Console.Write("Welcome to the system: " + myName);
        }

 

 

OddOrEven()

Spoiler

private static void OddOrEven()
        {
            int number = 0;
            while (int.TryParse(Console.ReadLine(),out number)==false)
            {
                Console.WriteLine("Thats not a number. Try typing a number.");
            }
            Console.WriteLine(number % 2 == 0 ? "even" : "odd");
        }

 

 

AverageOfFive()

Spoiler

private static void AverageOfFive()
        {
            int[] array1 = new int[5];
            Console.WriteLine("please give me 5 numbers and i will calculate the average");
            Console.WriteLine("Confirm each number by hitting 'Enter'");

            for (int i = 0; i < array1.Length; i++)
            {
                while (int.TryParse(Console.ReadLine(), out array1[i]) == false)
                {
                    Console.WriteLine("Thats not a number. Try typing a number.");
                }
            }
            Console.WriteLine("The average is: {0}", array1.Average());
        }

 

 

 

3 minutes ago, Daniboi said:

{
    class Program
    {
        static void Main(string[] args)
        {

            string userChoice;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("            Please pick an option between 1 and 5");
            Console.WriteLine("\n1.Tell me 10 names and i will say them back");
            Console.WriteLine("\n2.average of 5 numbers");
            Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
            Console.WriteLine("\n4.Welcomes you to the system");
            Console.WriteLine("\nQuit is 0");
            userChoice = Console.ReadLine();

            



            switch (Console.ReadKey().KeyChar)
            {
                case '1':
                    Console.Clear();
                    NameRepeat();
                    break;
                case '2':
                    Console.Clear();
                    AverageOfFive();
                    break;
                case '3':
                    Console.Clear();
                    OddOrEven();
                    break;
                case '4':
                    Console.Clear();
                    Welcome();
                    break;
                case '0':
                    Console.Clear();
                    Quit();
                    break;
            }





            //1
            void NameRepeat()
            {
                string[] array1 = new string[10];

                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("please give me 10 names and i will repeat them to you");
                    Console.ReadLine();
                    Console.Write("The name of the person is :" + i);
                }
            }







            //4

            void Welcome()
            {
                string myName = "";
                Console.Write("Please enter your name: ");
                myName = Console.ReadLine(); Console.Write("Welcome to the sytem: " + myName);
            }


            //3
            void OddOrEven()
            {
                Console.WriteLine(int.Parse(Console.ReadLine()) % 2 == 0 ? "even" : "odd");
            }






            //0
            void Quit()
            {

                Environment.Exit(0);

            }



            //2
            void AverageOfFive()
            {
                string[] cijfers = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                int i = 0;
                int sum = 0;
                for (i = 0; i < 5; i++)
                {
                    Console.Write("The average is: {0}", sum / 5);

                }

            }
        }
    }
}

 

check you brackets { }. you need to close the main function before declaring the other functions

I am very new to c# and have very little clue how to fix my code and c# in general and I have being using and finding whatever code looks relevant. I have been set a piece which says that it must do the following:

Create a program that has a menu with 5 options:

Option 1 - Ask the user for 10 first names and then output them in the format: User #1 is <Name>>
User #2 is <<Name>> etc
Option 2-Ask for 5 numbers and calculate the average
Option 3-Ask the user for a number and tell them whether it is an even number or an odd number
Option 4 - Ask for someone's name and then display 'Welcome to the system <<Name>>
Option 5=Exit the program.


From what i have learnt i a switch statement would be best however it seems to only go to the first option and then when i commented that out that line and tried to see wether or not it was a switch statement or code error. However that left me more confused than when i started with. At this point i am banging two rocks togther and seeing what happens.

____________________________________________________________________________________________________
 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string userChoice;
    
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("            Please pick an option between 1 and 5");
                Console.WriteLine("\n1.Tell me 10 names and i will say them back");
                Console.WriteLine("\n2.average of 5 numbers");
                Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
                Console.WriteLine("\n4.Welcomes you to the system");
                Console.WriteLine("\nQuit is 0");
                userChoice = Console.ReadLine();
    
                //1
                NameRepeat();
    
    
                //2
    
                AverageOfFive();
    
                //0
                Quit();
    
                //3
                OddOrEven();
    
                //4
    
                Welcome();
    
    
    
    
    
                switch (userChoice)
                {
                    case "1":
                        NameRepeat();
                        break;
                    case "2":
                        AverageOfFive();
                        break;
                    case "3":
                        OddOrEven();
                        break;
                    case "4":
                        Welcome();
                        break;
                    case "0":
                        Quit();
                        break;
                }
            }
    
    
    
            //1
            private static void NameRepeat()
            {
                string[] array1 = new string[10];
    
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("please give me 10 names and i will repeat them to you");
                    Console.ReadLine();
                    Console.Write("The name of the person is :" + i);
                }
            }
    
    
    
    
    
    
    
            //4
    
            private static void Welcome()
            {
                string myName = "";
                Console.Write("Please enter your name: ");
                myName = Console.ReadLine(); Console.Write("Welcome to the sytem: " + myName);
            }
    
    
            //3
            private static void OddOrEven()
            {
                Console.WriteLine(int.Parse(Console.ReadLine()) % 2 == 0 ? "even" : "odd");
            }
    
    
    
    
    
    
            //0
            private static void Quit()
            {
    
                Environment.Exit(0);
    
            }
    
    
    
            //2
            private static void AverageOfFive()
            {
                string[] cijfers = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                int i = 0;
                int sum = 0;
                for (i = 0; i < 5; i++)
                {
                     Console.Write("The average is: {0}", sum / 5);
                   
                }
    
            }
        }
    }

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/
Share on other sites

Link to post
Share on other sites

what exactly are you trying to achive with this

				//1
                NameRepeat();
    
    
                //2
    
                AverageOfFive();
    
                //0
                Quit();
    
                //3
                OddOrEven();
    
                //4
    
                Welcome();

 

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043356
Share on other sites

Link to post
Share on other sites

1 minute ago, cluelessgenius said:

what exactly are you trying to achive with this


				//1
                NameRepeat();
    
    
                //2
    
                AverageOfFive();
    
                //0
                Quit();
    
                //3
                OddOrEven();
    
                //4
    
                Welcome();

 

i am trying to complete the task:

 

1) Create a program that has a menu with 5 options:

 

Option 1 - Ask the user for 10 first names and then output them in the format: User #1 is <Name>>

User #2 is <<Name>> etc

Option 2-Ask for 5 numbers and calculate the average

Option 3-Ask the user for a number and tell them whether it is an even number or an odd number

Option 4 - Ask for someone's name and then display 'Welcome to the system <<Name>>

Option 5=Exit the program

 

however it locked on the first option and doesnt do any others.

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043359
Share on other sites

Link to post
Share on other sites

7 minutes ago, Daniboi said:

i am trying to complete the task:

 

1) Create a program that has a menu with 5 options:

 

 

 

Option 1 - Ask the user for 10 first names and then output them in the format: User #1 is <Name>>

 

User #2 is <<Name>> etc

 

Option 2-Ask for 5 numbers and calculate the average

 

Option 3-Ask the user for a number and tell them whether it is an even number or an odd number

 

Option 4 - Ask for someone's name and then display 'Welcome to the system <<Name>>

 

Option 5=Exit the program

 

 

however it locked on the first option and doesnt do any others.

well the part i commented you can delete and then it should work. what you are doing is calling all function before switching.

 

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043384
Share on other sites

Link to post
Share on other sites

heres my version of your code, ask if somethings unclear.

static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("            Please pick an option between 1 and 5");
                Console.WriteLine("\n1.Tell me 10 names and i will say them back");
                Console.WriteLine("\n2.average of 5 numbers");
                Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
                Console.WriteLine("\n4.Welcomes you to the system");
                Console.WriteLine("\nQuit is 0");

                switch (Console.ReadKey().KeyChar)
                {
                    case '1':
                        Console.Clear();
                        NameRepeat();
                        break;
                    case '2':
                        Console.Clear();
                        AverageOfFive();
                        break;
                    case '3':
                        Console.Clear();
                        OddOrEven();
                        break;
                    case '4':
                        Console.Clear();
                        Welcome();
                        break;
                    case '0':
                        Console.Clear();
                        Quit();
                        break;
                }

                Console.WriteLine("\nPress any Key to continue...");
                Console.ReadKey();
            }
        }

not perfect but a bit more elegant

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043389
Share on other sites

Link to post
Share on other sites

Oh hey, a fellow Dutch person

Please use the CODE function on the forum to insert code!

image.png.eb34e6a1240905060052c9059571a182.png

 

Anyways, onto the code.. Could you be a little more specific on what is and is not working right now?

 

The way you should tackle this code homework is in this way:

Ask for input, but keep in mind a user could input something wrong (e.g. you're asking for a number, but they can input a letter, so anticipate).

Something like this:

bool inputGood = false;
while(inputGood == false)
{
	// Check if the input is good. Convert to an int and check if that falls within the range the user can choice
    // Only set the inputGood to true once that is all good.
}

 

Then you have you switch case.. Which normally should really have a 'default' case for the reason listed above, but if you filter out the bad stuff beforehand it's not really necessary.. But good practice.

 

Assignment 1 should be done in 2 steps IMO.

1. Ask for 10 names

2. Print 10 names.

So first a for loop to get all the input, then another loop to print them all.

 

Assignment 2

You don't ask for user input here.. If you figure it out in assignment 1, that shouldn't be too hard.

Also, it's kind of ... Odd you initialize variable 'i' outside of the for loop... 

 

Assignment 3 looks good. I love the one-liner approach!

But I would still add the same as I said above though; sanitize your user input!

Another good addition to that part would be parameters and return values. Something like this:

 private static bool OddOrEven(int input)
{
      return (input % 2 == 0 ? true : false);
}

This makes it way easier to re-use this method later on too!

 

Assignment 4. That looks alright. Not how I would code it (since I would probably split the asking for a name and welcome message printing), but looks good.

If I were you, I would first start off with trying to make it so the right functions get called, you ask for the user input the right ways and then focus a bit on parameters and return variables.

 

To give the odd/even thing away and to help you get started I will give you this code:

static void Main(string[] args)
{
	// Ask for input and check if it's good. Otherwise, ask again
    int userInput = someNumber;
    
	// How to call the function
    bool isItOdd = OddOrEven(someNumber);    
    
    // How to read out what is give you back
    if(isItOdd)
    {
    	Console.WriteLine("Number is even");
    }
    else
    {
    	Console.WriteLine("Number is odd");    	
    }
}

// The function itself
private static bool OddOrEven(int input)
{
      return (input % 2 == 0 ? true : false);
}

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043419
Share on other sites

Link to post
Share on other sites

7 minutes ago, Daniboi said:

yeah that didnt work . could you explain for me in very simple terms what i have done wrong (i am a bit of a dummie)

NameRepeat();

this calls the function named 'NameRepeat'. you only want to do that when selected, so inside your switch case. but call it way before your switch case. 

same goes for the rest of them. 

have you looked at my code? it should work.

 

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043429
Share on other sites

Link to post
Share on other sites

yeah it

1 minute ago, cluelessgenius said:

NameRepeat();

this calls the function named 'NameRepeat'. you only want to do that when selected, so inside your switch case. but call it way before your switch case. 

same goes for the rest of them. 

have you looked at my code? it should work.

 

yeah i did and the same thing happens.

 

image.png.f799826b916034b664111ecccdf1de97.png

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043442
Share on other sites

Link to post
Share on other sites

3 minutes ago, Daniboi said:

yeah it

yeah i did and the same thing happens.

 

image.png.f799826b916034b664111ecccdf1de97.png

could you show me your main function again? something isnt right

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043451
Share on other sites

Link to post
Share on other sites

{
    class Program
    {
        static void Main(string[] args)
        {

            string userChoice;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("            Please pick an option between 1 and 5");
            Console.WriteLine("\n1.Tell me 10 names and i will say them back");
            Console.WriteLine("\n2.average of 5 numbers");
            Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
            Console.WriteLine("\n4.Welcomes you to the system");
            Console.WriteLine("\nQuit is 0");
            userChoice = Console.ReadLine();

            



            switch (Console.ReadKey().KeyChar)
            {
                case '1':
                    Console.Clear();
                    NameRepeat();
                    break;
                case '2':
                    Console.Clear();
                    AverageOfFive();
                    break;
                case '3':
                    Console.Clear();
                    OddOrEven();
                    break;
                case '4':
                    Console.Clear();
                    Welcome();
                    break;
                case '0':
                    Console.Clear();
                    Quit();
                    break;
            }





            //1
            void NameRepeat()
            {
                string[] array1 = new string[10];

                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("please give me 10 names and i will repeat them to you");
                    Console.ReadLine();
                    Console.Write("The name of the person is :" + i);
                }
            }







            //4

            void Welcome()
            {
                string myName = "";
                Console.Write("Please enter your name: ");
                myName = Console.ReadLine(); Console.Write("Welcome to the sytem: " + myName);
            }


            //3
            void OddOrEven()
            {
                Console.WriteLine(int.Parse(Console.ReadLine()) % 2 == 0 ? "even" : "odd");
            }






            //0
            void Quit()
            {

                Environment.Exit(0);

            }



            //2
            void AverageOfFive()
            {
                string[] cijfers = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                int i = 0;
                int sum = 0;
                for (i = 0; i < 5; i++)
                {
                    Console.Write("The average is: {0}", sum / 5);

                }

            }
        }
    }
}

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043480
Share on other sites

Link to post
Share on other sites

So usually im not a fan of just giving out answers because i dont want to rob you of the learning effect but i gotta go right now and since i dont know wether im gonna be on today later im gonna post one of many possible solutions - namely my own solution - to this task in a spoiler. feel free to use it but id rather you try and understand whats happening if this isnt as urgent then ill be back tommorrow and gladly help you understand as best i can

 

main()

Spoiler

static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("            Please pick an option between 1 and 5");
                Console.WriteLine("\n1.Tell me 10 names and i will say them back");
                Console.WriteLine("\n2.average of 5 numbers");
                Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
                Console.WriteLine("\n4.Welcomes you to the system");
                Console.WriteLine("\nQuit is 0");

                switch (Console.ReadKey().KeyChar)
                {
                    case '1':
                        Console.Clear();
                        NameRepeat();
                        break;
                    case '2':
                        Console.Clear();
                        AverageOfFive();
                        break;
                    case '3':
                        Console.Clear();
                        OddOrEven();
                        break;
                    case '4':
                        Console.Clear();
                        Welcome();
                        break;
                    case '0':
                        Console.Clear();
                        Quit();
                        break;
                }

                Console.WriteLine("\nPress any Key to continue...");
                Console.ReadKey();
            }
        }

 

 

NameRepeat()

Spoiler

private static void NameRepeat()
        {
            string[] array1 = new string[10];
            Console.WriteLine("please give me 10 names and i will repeat them to you");
            Console.WriteLine("Confirm each Name by hitting 'Enter'");

            for (int i = 0; i < array1.Length; i++)
            {
                array1[i] = Console.ReadLine();
            }
            for (int j = 0; j < array1.Length; j++)
            {
                Console.WriteLine("User " + j + " is :" + array1[j]);
            }
        }

 

 

Welcome()

Spoiler

private static void Welcome()
        {
            Console.Write("Please enter your name: ");
            string myName = Console.ReadLine();
            Console.Write("Welcome to the system: " + myName);
        }

 

 

OddOrEven()

Spoiler

private static void OddOrEven()
        {
            int number = 0;
            while (int.TryParse(Console.ReadLine(),out number)==false)
            {
                Console.WriteLine("Thats not a number. Try typing a number.");
            }
            Console.WriteLine(number % 2 == 0 ? "even" : "odd");
        }

 

 

AverageOfFive()

Spoiler

private static void AverageOfFive()
        {
            int[] array1 = new int[5];
            Console.WriteLine("please give me 5 numbers and i will calculate the average");
            Console.WriteLine("Confirm each number by hitting 'Enter'");

            for (int i = 0; i < array1.Length; i++)
            {
                while (int.TryParse(Console.ReadLine(), out array1[i]) == false)
                {
                    Console.WriteLine("Thats not a number. Try typing a number.");
                }
            }
            Console.WriteLine("The average is: {0}", array1.Average());
        }

 

 

 

3 minutes ago, Daniboi said:

{
    class Program
    {
        static void Main(string[] args)
        {

            string userChoice;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("            Please pick an option between 1 and 5");
            Console.WriteLine("\n1.Tell me 10 names and i will say them back");
            Console.WriteLine("\n2.average of 5 numbers");
            Console.WriteLine("\n3.Ask the user for a number and tell them whether it is an even number or an odd number");
            Console.WriteLine("\n4.Welcomes you to the system");
            Console.WriteLine("\nQuit is 0");
            userChoice = Console.ReadLine();

            



            switch (Console.ReadKey().KeyChar)
            {
                case '1':
                    Console.Clear();
                    NameRepeat();
                    break;
                case '2':
                    Console.Clear();
                    AverageOfFive();
                    break;
                case '3':
                    Console.Clear();
                    OddOrEven();
                    break;
                case '4':
                    Console.Clear();
                    Welcome();
                    break;
                case '0':
                    Console.Clear();
                    Quit();
                    break;
            }





            //1
            void NameRepeat()
            {
                string[] array1 = new string[10];

                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("please give me 10 names and i will repeat them to you");
                    Console.ReadLine();
                    Console.Write("The name of the person is :" + i);
                }
            }







            //4

            void Welcome()
            {
                string myName = "";
                Console.Write("Please enter your name: ");
                myName = Console.ReadLine(); Console.Write("Welcome to the sytem: " + myName);
            }


            //3
            void OddOrEven()
            {
                Console.WriteLine(int.Parse(Console.ReadLine()) % 2 == 0 ? "even" : "odd");
            }






            //0
            void Quit()
            {

                Environment.Exit(0);

            }



            //2
            void AverageOfFive()
            {
                string[] cijfers = new string[10] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
                int i = 0;
                int sum = 0;
                for (i = 0; i < 5; i++)
                {
                    Console.Write("The average is: {0}", sum / 5);

                }

            }
        }
    }
}

 

check you brackets { }. you need to close the main function before declaring the other functions

"You know it'll clock down as soon as it hits 40°C, right?" - "Yeah ... but it doesnt hit 40°C ... ever  😄"

 

GPU: MSI GTX1080 Ti Aero @ 2 GHz (watercooled) CPU: Ryzen 5600X (watercooled) RAM: 32GB 3600Mhz Corsair LPX MB: Gigabyte B550i PSU: Corsair SF750 Case: Hyte Revolt 3

 

Link to comment
https://linustechtips.com/topic/1123299-c-help/#findComment-13043491
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×