Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- //The value returned from the topmenu method is stored in a variable called useroption
- ChooseOption();
- Console.ReadKey();
- }
- static void ChooseOption()
- {
- int useroption;
- // excute while loop untill option is not 1-3
- do
- {
- useroption = topmenu();
- if (useroption == 1)
- {
- Console.Clear();
- Createname();
- //break;
- }
- if (useroption == 2)
- {
- Console.Clear();
- factorial();
- // break;
- }
- if (useroption == 3)
- {
- Console.Clear();
- Console.WriteLine("Thank you for using my program, Good bye !!!");
- //break;
- }
- //topmenu();
- }
- while (useroption != 3);
- }
- static int topmenu()
- {
- int option;
- string option_str;
- Console.Clear();
- Console.WriteLine("********************************************************************************");
- Console.WriteLine("********************************************************************************");
- Console.WriteLine("********* OPTION 1 : Enter your name *********");
- Console.WriteLine("********* OPTION 2 : Enter the number you want to factorise *********");
- Console.WriteLine("********* OPTION 3 : Quit *********");
- Console.WriteLine("********************************************************************************");
- Console.WriteLine("********************************************************************************");
- option_str = Console.ReadLine();
- option = Convert.ToInt32(option_str);
- Console.Clear();
- if (option < 0 || option > 3)
- {
- Console.WriteLine("You have enter an invald option,");
- Console.WriteLine("Please chose a option between 1-3 (Please press any key to return to main menu)");
- Console.ReadLine();
- Console.Clear();
- //topmenu();
- ChooseOption();
- }
- else
- {
- Console.WriteLine("You have chosen option: " + option + " (Please press any key continue)");
- }
- Console.ReadKey();
- return option;
- }
- static void Createname()
- {
- string firstname, surname, firstname_str, surname_str, userfullname;
- Console.Clear();
- Console.WriteLine("Please enter your first name ");
- firstname_str = Console.ReadLine();
- firstname = Convert.ToString(firstname_str);
- Console.Clear();
- Console.WriteLine("Please enter your surname name ");
- surname_str = Console.ReadLine();
- surname = Convert.ToString(surname_str);
- Console.Clear();
- userfullname = firstname + surname;
- Console.WriteLine("You have entered your name as " + firstname[0] + "." + surname);
- Console.WriteLine("(Please press any key to return to main menu)");
- Console.ReadKey();
- //topmenu();
- //ChooseOption();
- return;
- }
- static void factorial()
- {
- string number_str;
- double factorial = 1;
- Console.WriteLine("Please enter number");
- number_str = Console.ReadLine();
- int num = Convert.ToInt32(number_str);
- // If statement is used so when the user inputs 0, INVALID is outputed
- if (num <= 0)
- {
- Console.WriteLine("You have enter an invald option");
- Console.WriteLine("Please enter number");
- number_str = Console.ReadLine();
- Console.Clear();
- num = Convert.ToInt32(number_str);
- //Console.Clear();
- //topmenu();
- //number_str = Console.ReadLine();
- }
- if (num >= 0)
- {
- while (num != 0)
- {
- for (int i = num; i >= 1; i--)
- {
- factorial = factorial * i;
- Console.Write(i + " * ");
- }
- Console.WriteLine("= "+factorial+ " which is factorial of " + number_str.ToString() );
- Console.WriteLine("(please any key to return to main menu)");
- Console.ReadKey();
- Console.Clear();
- break;
- //topmenu();
- //ChooseOption();
- }
- }
- //return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement