Advertisement
Guest User

Program1

a guest
Oct 25th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.37 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             //The value returned from the topmenu method is stored in a variable called useroption
  4.             ChooseOption();
  5.             Console.ReadKey();
  6.         }
  7. static void ChooseOption()
  8.     {
  9.         int useroption;
  10.         // excute while loop untill option is not 1-3
  11.         do
  12.         {
  13.  
  14.             useroption = topmenu();
  15.  
  16.             if (useroption == 1)
  17.             {
  18.                 Console.Clear();
  19.                 Createname();
  20.                 //break;
  21.             }
  22.  
  23.             if (useroption == 2)
  24.             {
  25.                 Console.Clear();
  26.                 factorial();
  27.                 // break;
  28.             }
  29.  
  30.             if (useroption == 3)
  31.             {
  32.                 Console.Clear();
  33.                 Console.WriteLine("Thank you for using my program, Good bye !!!");
  34.                 //break;
  35.             }
  36.  
  37.             //topmenu();
  38.         }
  39.         while (useroption != 3);
  40.     }
  41. static int topmenu()
  42. {
  43.     int option;
  44.     string option_str;
  45.  
  46.     Console.Clear();
  47.     Console.WriteLine("********************************************************************************");
  48.     Console.WriteLine("********************************************************************************");
  49.     Console.WriteLine("*********      OPTION 1 : Enter your name                              *********");
  50.     Console.WriteLine("*********      OPTION 2 : Enter the number you want to factorise       *********");
  51.     Console.WriteLine("*********      OPTION 3 : Quit                                         *********");
  52.     Console.WriteLine("********************************************************************************");
  53.     Console.WriteLine("********************************************************************************");
  54.     option_str = Console.ReadLine();
  55.  
  56.     option = Convert.ToInt32(option_str);
  57.     Console.Clear();
  58.  
  59.     if (option < 0 || option > 3)
  60.     {
  61.         Console.WriteLine("You have enter an invald option,");
  62.         Console.WriteLine("Please chose a option between 1-3 (Please press any key to return to main menu)");
  63.         Console.ReadLine();
  64.         Console.Clear();
  65.         //topmenu();
  66.         ChooseOption();
  67.     }
  68.     else
  69.     {
  70.         Console.WriteLine("You have chosen option: " + option + " (Please press any key continue)");
  71.     }
  72.     Console.ReadKey();
  73.     return option;
  74. }
  75. static void Createname()
  76. {
  77.     string firstname, surname, firstname_str, surname_str, userfullname;
  78.  
  79.     Console.Clear();
  80.     Console.WriteLine("Please enter your first name ");
  81.     firstname_str = Console.ReadLine();
  82.     firstname = Convert.ToString(firstname_str);
  83.     Console.Clear();
  84.     Console.WriteLine("Please enter your surname name ");
  85.     surname_str = Console.ReadLine();
  86.     surname = Convert.ToString(surname_str);
  87.     Console.Clear();
  88.     userfullname = firstname + surname;
  89.  
  90.     Console.WriteLine("You have entered your name as " + firstname[0] + "." + surname);
  91.     Console.WriteLine("(Please press any key to return to main menu)");
  92.     Console.ReadKey();
  93.     //topmenu();
  94.     //ChooseOption();
  95.     return;
  96.  
  97. }
  98. static void factorial()
  99. {
  100.  
  101.  
  102.     string number_str;
  103.     double factorial = 1;
  104.  
  105.  
  106.  
  107.     Console.WriteLine("Please enter number");
  108.     number_str = Console.ReadLine();
  109.  
  110.     int num = Convert.ToInt32(number_str);
  111.  
  112.  
  113.     // If statement is used so when the user inputs 0, INVALID is outputed
  114.  
  115.     if (num <= 0)
  116.     {
  117.         Console.WriteLine("You have enter an invald option");
  118.         Console.WriteLine("Please enter number");
  119.         number_str = Console.ReadLine();
  120.         Console.Clear();
  121.  
  122.  
  123.         num = Convert.ToInt32(number_str);
  124.         //Console.Clear();
  125.         //topmenu();
  126.         //number_str = Console.ReadLine();
  127.     }
  128.  
  129.     if (num >= 0)
  130.     {
  131.  
  132.         while (num != 0)
  133.         {
  134.             for (int i = num; i >= 1; i--)
  135.             {
  136.                 factorial = factorial * i;
  137.                 Console.Write(i + " * ");
  138.  
  139.             }
  140.  
  141.  
  142.                 Console.WriteLine("= "+factorial+ " which is factorial of " + number_str.ToString() );
  143.                 Console.WriteLine("(please any key to return to main menu)");
  144.                 Console.ReadKey();
  145.                 Console.Clear();
  146.                 break;
  147.                 //topmenu();
  148.                 //ChooseOption();
  149.  
  150.         }
  151.  
  152.     }
  153.  
  154.     //return;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement