Exemple #1
0
        static void Main(string[] args)
        {
            Tipper tipper = new Tipper();

            bool keepLooping = true;

            while (keepLooping)
            {
                Console.Write("How much is the bill?");
                string billInput = Console.ReadLine();
                try
                {
                    tipper.BillAmount = double.Parse(billInput);
                }
                catch
                {
                    Console.WriteLine("Only numeric values are allowed");
                    continue;
                }

                Console.Write("B)ad tip O)k tip G)ood Tip D)ivvy the bill Q)uit: ");
                string selection = Console.ReadLine().ToUpper();

                switch (selection[0])
                {
                case 'B':
                    Console.WriteLine("You should tip {0:C}.", tipper.CalculateTip(0.1));
                    break;

                case 'O':
                    Console.WriteLine("You should tip {0:C}", tipper.CalculateTip());
                    break;

                case 'G':
                    Console.WriteLine("You should tip {0:C}.", tipper.CalculateTip(0.2));
                    break;

                case 'D':
                    Console.WriteLine("How many people are splitting the bill?");
                    string peopleNumber = Console.ReadLine();
                    try
                    {
                        Console.WriteLine("Each should pay {0:C}", tipper.Divvy(int.Parse(peopleNumber)));
                    }
                    catch
                    {
                        Console.WriteLine("Only numeric values are allowed!");
                    }
                    break;

                case 'Q':
                    keepLooping = false;
                    break;

                default:
                    Console.WriteLine("Only the letters B,O,G,D and Q are accepted as input.");
                    break;
                }
            }
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            Tipper tipper = new Tipper();

            while (true)
            {
                Console.Write("Please enter check amount: ");
                tipper.TotalBill = double.Parse(Console.ReadLine());

                Console.Write("B)ad tip O)k tip G)ood Tip D)ivvy the bill Q)uit: ");
                char operation = Console.ReadLine().ToUpper()[0];

                if (operation == 'Q')
                {
                    break;
                }

                double userInput = 0.0;

                switch (operation)
                {
                case 'B':
                    userInput = tipper.CalculateTip(0.10);
                    break;

                case 'O':
                    userInput = tipper.CalculateTip();     // 15%
                    break;

                case 'G':
                    userInput = tipper.CalculateTip(0.20);
                    break;

                case 'D':
                    Console.Write("Number of people? ");
                    int numPeople = int.Parse(Console.ReadLine());
                    userInput = tipper.Divvy(numPeople);
                    break;

                default:
                    Console.WriteLine("Please enter B, O, G, D or Q");
                    break;
                }

                Console.WriteLine("Answer: {0}", userInput);
            }

            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Tipper tipper = new Tipper(); // instance of the tipper class

            while (true)                  // "forever" loop
            {
                Console.Write("Please enter the total bill: ");
                tipper.total_bill = double.Parse(Console.ReadLine());

                Console.Write("B)ad tip O)k tip G)ood Tip D)ivvy the bill Q)uit: ");
                char operation = Console.ReadLine().ToUpper()[0];

                if (operation == 'B')
                {
                    double total_bad = tipper.CalculateTip(.1);
                    Console.WriteLine("It was a bad tip, the total is: " + total_bad);
                }
                else if (operation == 'O')
                {
                    double total_okay = tipper.CalculateTip();
                    Console.WriteLine("It was a okay tip, the total is: " + total_okay);
                }
                else if (operation == 'G')
                {
                    double total_good = tipper.CalculateTip(.2);
                    Console.WriteLine("It was a good tip, the total is: " + total_good);
                }
                else if (operation == 'D')
                {
                    Console.Write("How many people are there?: ");
                    tipper.total_people = int.Parse(Console.ReadLine());

                    Console.WriteLine("The total was: " + tipper.Divvy(tipper.total_people));
                }
                else if (operation == 'Q')
                {
                    break;
                }
            }
        }