First of all, your for loop at the end (the one which gave you an error). Contains a misspelled property. The
integer_array.length
should actually be
integer_array.Length
The ‘length’ property is ‘Length’ in C#
And for making sure that your code is looped until any of the correct input keys have been pressed.
You can encapsulate your whole code body with
while(true) {
// Your code here
}
And then make sure that at the very end; inside each if statement. You should add the keyword
break;
Except for the last one of course.
And last thing.
For seperating each if statement into their own functions, all you have to do is… (For example)
Change the following code
else if (option == 2)
{
Console.Clear();
Console.WriteLine(" --- Random Number Generator --- ");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" Help Menu");
Console.WriteLine();
Console.WriteLine("To navigate through the program type in the number related to the task then press enter.For example To exit the program press 4 and then press enter.");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press any key to Exit");
}
Into
else if (option == 2)
{
OpenHelpMenu();
}
And then at the end of the file; before the last two closing brackets }
Add a new function
void OpenHelpMenu() {
Console.Clear();
Console.WriteLine(" --- Random Number Generator --- ");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" Help Menu");
Console.WriteLine();
Console.WriteLine("To navigate through the program type in the number related to the task then press enter.For example To exit the program press 4 and then press enter.");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press any key to Exit");
}
Repeat with each if statement and you should be fine 🙂
solved C#, How to make and call functions