TheBulgarianWolf

Order Calculator

Oct 29th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Enter the product you want: ");
  10.             string product = Console.ReadLine();
  11.             Console.Write("Enter the quantity you want: ");
  12.             int quantity = int.Parse(Console.ReadLine());
  13.             Console.WriteLine("The price is: {0:F2}",Order(product,quantity));
  14.            
  15.         }
  16.  
  17.         static double Order(string product,int quantity)
  18.         {
  19.             double sum = 0;
  20.             double coffeePrice = 1.5;
  21.             double waterPrice = 1;
  22.             double cokePrice = 1.4;
  23.             double snacksPrice = 2;
  24.            
  25.             switch (product)
  26.             {
  27.                 case "coffee":
  28.                     sum = coffeePrice * quantity;
  29.                     break;
  30.                 case "water":
  31.                     sum = waterPrice * quantity;
  32.                     break;
  33.                 case "coke":
  34.                     sum = cokePrice * quantity;
  35.                     break;
  36.                 case "snacks":
  37.                     sum = snacksPrice * quantity;
  38.                     break;
  39.                 default:
  40.                     sum = 0;
  41.                     break;
  42.             }
  43.  
  44.             return sum;
  45.         }
  46.  
  47.     }
  48. }
  49.  
Add Comment
Please, Sign In to add comment