Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8. class Variables //Variables stored globally for all methods
  9. {
  10. public static decimal busDist = 0; //Distance the bus travelled
  11. public static decimal trainDist = 0; //Distance the train travelled
  12. public static decimal taxiDist = 0; //Distance the taxi travelled
  13. public static decimal busPass = 0; //Cost of the bus pass
  14. public static decimal trainTicket = 0; //Cost of the train ticket
  15. public static decimal taxiFare = 0; //Cost of the taxi fare
  16. public static decimal busCost = 0; //Cost of the bus per mile
  17. public static decimal trainCost = 0; //Cost of the train per mile
  18. public static decimal taxiCost = 0; //Cost of the taxi per mile
  19. public static decimal perCarDist = 0; //Distance travelled in personal car
  20. public static decimal perCarFuel = 0; //Cost of the personal car fuel
  21. public static decimal perCarCost = 0; //Cost of the personal car per mile
  22.  
  23. }
  24.  
  25. class Program //Contains all the methods used in the program
  26. {
  27. static void Main(string[] args) //Handover to Login
  28. {
  29. Login();
  30. }
  31.  
  32. static void Login()
  33. {
  34. //Login
  35. string Username = "";
  36. string Password = "";
  37. string[] User = { "Jack", "Ryan", "Matty" };
  38. string[] Pass = { "123", "123", "123" };
  39.  
  40. {
  41. Console.WriteLine("Username?");
  42. Username = Console.ReadLine();
  43. Console.WriteLine("Password?");
  44. Password = Console.ReadLine();
  45. //Detects if the user enters the correct Username and Password
  46.  
  47. for (int i = 0; i < 3; i++)
  48.  
  49. if (Username == User[i] && Password == Pass[i])
  50. {
  51. Console.WriteLine("Success ");
  52. Menu();
  53. }
  54. Console.WriteLine("Unsuccessful attempt at login");
  55. Login();
  56. }
  57. } //Login
  58.  
  59. static void Menu()
  60. {
  61. int x = 1;
  62. while (x == 1)
  63. {
  64. string choice;
  65. Console.WriteLine("Select an option: \n 1. Calculate cost per mile \n 2. Using personal car for business \n 3. Exit the program");
  66. choice = Console.ReadLine().ToLower();
  67. if (choice == "1")
  68. {
  69. x = 0;
  70. Distance();
  71. }
  72. if (choice == "2")
  73. {
  74. Console.WriteLine("Success");
  75. x = 0;
  76. PerCar();
  77. }
  78. if (choice == "3")
  79. {
  80. System.Environment.Exit(0);
  81. }
  82. else
  83. Console.WriteLine("Please select an option");
  84. }
  85. } //Select whether to calculate distance or add usage for company car
  86.  
  87. static void Distance()
  88. {
  89. //Asks the user what the distance travelled by each medium was
  90.  
  91. Console.WriteLine("What is the distance travelled by bus in miles?");
  92. try
  93. {
  94. Variables.busDist = Convert.ToInt32(Console.ReadLine());
  95. }
  96. catch (SystemException)
  97. {
  98. Console.WriteLine("Error! Please write a number!");
  99. Distance();
  100. }
  101.  
  102. Console.WriteLine("What is the distance travelled by train in miles?");
  103.  
  104. try
  105. {
  106. Variables.trainDist = Convert.ToInt32(Console.ReadLine());
  107. }
  108. catch (SystemException)
  109. {
  110. Console.WriteLine("Error! Please write a number!");
  111. Distance();
  112. }
  113.  
  114. Console.WriteLine("What is the distance travelled by taxi? in miles");
  115. try
  116. {
  117. Variables.taxiDist = Convert.ToInt32(Console.ReadLine());
  118. }
  119. catch (SystemException)
  120. {
  121. Console.WriteLine("Error! Please write a number!");
  122. Distance();
  123. }
  124.  
  125.  
  126. Price();
  127. } //Input distance per travel medium in miles
  128.  
  129. static void Price()
  130. {
  131. //asks user what the cost of travel was
  132.  
  133. Console.WriteLine("What is the cost of the bus pass in £?");
  134.  
  135. try
  136. {
  137. Variables.busPass = Convert.ToInt32(Console.ReadLine()); //Tries to get the input from the user
  138. }
  139. catch (SystemException)
  140. {
  141. Console.WriteLine("Error! Please write a number!"); //Only runs if the input is in an incorrect format
  142. Price();
  143. }
  144.  
  145. Console.WriteLine("What is the cost of the train ticket in £?");
  146.  
  147. try
  148. {
  149. Variables.trainTicket = Convert.ToInt32(Console.ReadLine());
  150. }
  151. catch (SystemException)
  152. {
  153. Console.WriteLine("Error! Please write a number!");
  154. Price();
  155. }
  156.  
  157. Console.WriteLine("What is the cost of the taxi fare in £?");
  158.  
  159. try
  160. {
  161. Variables.taxiFare = Convert.ToInt32(Console.ReadLine());
  162. }
  163. catch (SystemException)
  164. {
  165. Console.WriteLine("Error! Please write a number!");
  166. Price();
  167. }
  168.  
  169.  
  170. TotalCost();
  171.  
  172. } //Input cost of pass/ticket/fare
  173.  
  174. static void TotalCost()
  175. {
  176. //Works out the cost per mile was
  177.  
  178. Variables.busCost = Math.Round(Variables.busPass / Variables.busDist, 2);
  179. Console.WriteLine("Bus costs £" + Variables.busCost + " per mile");
  180.  
  181. Variables.trainCost = Math.Round(Variables.trainTicket / Variables.trainDist, 2);
  182. Console.WriteLine("train costs £" + Variables.trainCost + " per mile");
  183.  
  184. Variables.taxiCost = Math.Round(Variables.taxiFare / Variables.taxiDist, 2);
  185.  
  186. Console.WriteLine("taxi costs £" + Variables.taxiCost + " per mile");
  187. LeastExpensive();
  188.  
  189. } //Calculates cost of each medium per mile
  190.  
  191. static void LeastExpensive()
  192. {
  193. if (Variables.taxiCost == Variables.busCost && Variables.busCost == Variables.trainCost && Variables.trainCost == Variables.taxiCost)
  194. {
  195. Console.WriteLine("All mediums of travel cost the same");
  196. }
  197.  
  198. else if (Variables.trainCost >= Variables.taxiCost && Variables.taxiCost > Variables.busCost)
  199. {
  200.  
  201. Console.WriteLine("Bus is cheapest, costing £" + Variables.busCost + " per mile.");
  202. }
  203.  
  204. else if (Variables.busCost >= Variables.taxiCost && Variables.taxiCost > Variables.trainCost)
  205. {
  206. Console.WriteLine("Train is cheapest, costing £" + Variables.trainCost + " per mile.");
  207. }
  208.  
  209. else if (Variables.busCost >= Variables.trainCost && Variables.trainCost > Variables.taxiCost)
  210. {
  211. Console.WriteLine("Taxi is cheapest, costing £" + Variables.taxiCost + " per mile.");
  212. }
  213.  
  214. else if (Variables.taxiCost == Variables.busCost)
  215. Console.WriteLine("Bus and taxi both cost £" + Variables.busCost + " per mile");
  216.  
  217. else if (Variables.trainCost == Variables.busCost)
  218. Console.WriteLine("Bus and train both cost £" + Variables.busCost + " per mile");
  219.  
  220. else if (Variables.taxiCost == Variables.trainCost)
  221. Console.WriteLine("Train and taxi both cost £" + Variables.taxiCost + " per mile");
  222.  
  223.  
  224. Console.ReadKey();
  225. System.Environment.Exit(0);
  226. } //Outputs most expensive medium
  227.  
  228. static void PerCar()
  229. {
  230. Console.WriteLine("How far did you travel in miles?");
  231. try
  232. {
  233. Variables.perCarDist = Convert.ToInt32(Console.ReadLine());
  234. }
  235. catch (SystemException)
  236. {
  237. Console.WriteLine("Error! Please write a number!");
  238. PerCar();
  239. }
  240.  
  241. Console.WriteLine("How much fuel did you pay for in £?");
  242. try
  243. {
  244. Variables.perCarFuel = Convert.ToInt32(Console.ReadLine());
  245. }
  246. catch (SystemException)
  247. {
  248. Console.WriteLine("Error! Please write a number!");
  249. PerCar();
  250. }
  251.  
  252.  
  253. Variables.perCarCost = Math.Round(Variables.perCarFuel / Variables.perCarDist, 3);
  254. Console.WriteLine("Personal car costs £" + Variables.perCarCost + " per mile \nYou have been paid 45p per mile, £" + (Convert.ToInt32(Variables.perCarDist) * 0.45));
  255. Console.ReadKey();
  256. System.Environment.Exit(0);
  257.  
  258. } //calculates employee pay for miles
  259. }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement