JulianJulianov

05.MethodsLab-Orders

Feb 13th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. 5.  Orders
  2. Write a method that calculates the total price of an order and prints it on the console. The method should receive one of the following products: coffee, coke, water, snacks; and a quantity of the product. The prices for a single piece of each product are:
  3. • coffee – 1.50
  4. • water – 1.00
  5. • coke – 1.40
  6. • snacks – 2.00
  7. Print the result formatted to the second decimal place
  8. Example
  9. Input        Output
  10. water
  11. 5            5.00
  12. coffee
  13. 2            3.00
  14. Hints
  15. 1.  Read the first two lines
  16. 2.  Create a method the pass the two variables in
  17. 3.  Print the result in the method
  18.  
  19. using System;
  20.  
  21. namespace _05Orders
  22. {
  23.     class Program
  24.     {
  25.         static void Main(string[] args)
  26.         {
  27.             string product = Console.ReadLine();
  28.             var number = int.Parse(Console.ReadLine());
  29.  
  30.             PrintOrders(product, number);
  31.         }
  32.         private static void PrintOrders(string product, int number)
  33.         {
  34.             double sumPrice = 0;
  35.             if (product == "coffee")
  36.             {
  37.                 sumPrice = 1.50 * number;
  38.             }
  39.             else if (product == "water")
  40.             {
  41.                 sumPrice = 1.00 * number;
  42.             }
  43.             else if (product == "coke")
  44.             {
  45.                 sumPrice = 1.40 * number;
  46.             }
  47.             else if (product == "snacks")
  48.             {
  49.                 sumPrice = 2.00 * number;
  50.             }
  51.             Console.WriteLine($"{sumPrice:F2}");
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment