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
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 accountSign in
Already have an account? Sign in here.
Sign In Now