Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Variables //Variables stored globally for all methods
- {
- public static decimal busDist = 0; //Distance the bus travelled
- public static decimal trainDist = 0; //Distance the train travelled
- public static decimal taxiDist = 0; //Distance the taxi travelled
- public static decimal busPass = 0; //Cost of the bus pass
- public static decimal trainTicket = 0; //Cost of the train ticket
- public static decimal taxiFare = 0; //Cost of the taxi fare
- public static decimal busCost = 0; //Cost of the bus per mile
- public static decimal trainCost = 0; //Cost of the train per mile
- public static decimal taxiCost = 0; //Cost of the taxi per mile
- public static decimal perCarDist = 0; //Distance travelled in personal car
- public static decimal perCarFuel = 0; //Cost of the personal car fuel
- public static decimal perCarCost = 0; //Cost of the personal car per mile
- }
- class Program //Contains all the methods used in the program
- {
- static void Main(string[] args) //Handover to Login
- {
- Login();
- }
- static void Login()
- {
- //Login
- string Username = "";
- string Password = "";
- string[] User = { "Jack", "Ryan", "Matty" };
- string[] Pass = { "123", "123", "123" };
- {
- Console.WriteLine("Username?");
- Username = Console.ReadLine();
- Console.WriteLine("Password?");
- Password = Console.ReadLine();
- //Detects if the user enters the correct Username and Password
- for (int i = 0; i < 3; i++)
- if (Username == User[i] && Password == Pass[i])
- {
- Console.WriteLine("Success ");
- Menu();
- }
- Console.WriteLine("Unsuccessful attempt at login");
- Login();
- }
- } //Login
- static void Menu()
- {
- int x = 1;
- while (x == 1)
- {
- string choice;
- Console.WriteLine("Select an option: \n 1. Calculate cost per mile \n 2. Using personal car for business \n 3. Exit the program");
- choice = Console.ReadLine().ToLower();
- if (choice == "1")
- {
- x = 0;
- Distance();
- }
- if (choice == "2")
- {
- Console.WriteLine("Success");
- x = 0;
- PerCar();
- }
- if (choice == "3")
- {
- System.Environment.Exit(0);
- }
- else
- Console.WriteLine("Please select an option");
- }
- } //Select whether to calculate distance or add usage for company car
- static void Distance()
- {
- //Asks the user what the distance travelled by each medium was
- Console.WriteLine("What is the distance travelled by bus in miles?");
- try
- {
- Variables.busDist = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- Distance();
- }
- Console.WriteLine("What is the distance travelled by train in miles?");
- try
- {
- Variables.trainDist = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- Distance();
- }
- Console.WriteLine("What is the distance travelled by taxi? in miles");
- try
- {
- Variables.taxiDist = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- Distance();
- }
- Price();
- } //Input distance per travel medium in miles
- static void Price()
- {
- //asks user what the cost of travel was
- Console.WriteLine("What is the cost of the bus pass in £?");
- try
- {
- Variables.busPass = Convert.ToInt32(Console.ReadLine()); //Tries to get the input from the user
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!"); //Only runs if the input is in an incorrect format
- Price();
- }
- Console.WriteLine("What is the cost of the train ticket in £?");
- try
- {
- Variables.trainTicket = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- Price();
- }
- Console.WriteLine("What is the cost of the taxi fare in £?");
- try
- {
- Variables.taxiFare = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- Price();
- }
- TotalCost();
- } //Input cost of pass/ticket/fare
- static void TotalCost()
- {
- //Works out the cost per mile was
- Variables.busCost = Math.Round(Variables.busPass / Variables.busDist, 2);
- Console.WriteLine("Bus costs £" + Variables.busCost + " per mile");
- Variables.trainCost = Math.Round(Variables.trainTicket / Variables.trainDist, 2);
- Console.WriteLine("train costs £" + Variables.trainCost + " per mile");
- Variables.taxiCost = Math.Round(Variables.taxiFare / Variables.taxiDist, 2);
- Console.WriteLine("taxi costs £" + Variables.taxiCost + " per mile");
- LeastExpensive();
- } //Calculates cost of each medium per mile
- static void LeastExpensive()
- {
- if (Variables.taxiCost == Variables.busCost && Variables.busCost == Variables.trainCost && Variables.trainCost == Variables.taxiCost)
- {
- Console.WriteLine("All mediums of travel cost the same");
- }
- else if (Variables.trainCost >= Variables.taxiCost && Variables.taxiCost > Variables.busCost)
- {
- Console.WriteLine("Bus is cheapest, costing £" + Variables.busCost + " per mile.");
- }
- else if (Variables.busCost >= Variables.taxiCost && Variables.taxiCost > Variables.trainCost)
- {
- Console.WriteLine("Train is cheapest, costing £" + Variables.trainCost + " per mile.");
- }
- else if (Variables.busCost >= Variables.trainCost && Variables.trainCost > Variables.taxiCost)
- {
- Console.WriteLine("Taxi is cheapest, costing £" + Variables.taxiCost + " per mile.");
- }
- else if (Variables.taxiCost == Variables.busCost)
- Console.WriteLine("Bus and taxi both cost £" + Variables.busCost + " per mile");
- else if (Variables.trainCost == Variables.busCost)
- Console.WriteLine("Bus and train both cost £" + Variables.busCost + " per mile");
- else if (Variables.taxiCost == Variables.trainCost)
- Console.WriteLine("Train and taxi both cost £" + Variables.taxiCost + " per mile");
- Console.ReadKey();
- System.Environment.Exit(0);
- } //Outputs most expensive medium
- static void PerCar()
- {
- Console.WriteLine("How far did you travel in miles?");
- try
- {
- Variables.perCarDist = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- PerCar();
- }
- Console.WriteLine("How much fuel did you pay for in £?");
- try
- {
- Variables.perCarFuel = Convert.ToInt32(Console.ReadLine());
- }
- catch (SystemException)
- {
- Console.WriteLine("Error! Please write a number!");
- PerCar();
- }
- Variables.perCarCost = Math.Round(Variables.perCarFuel / Variables.perCarDist, 3);
- Console.WriteLine("Personal car costs £" + Variables.perCarCost + " per mile \nYou have been paid 45p per mile, £" + (Convert.ToInt32(Variables.perCarDist) * 0.45));
- Console.ReadKey();
- System.Environment.Exit(0);
- } //calculates employee pay for miles
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement