IordanRujinov

FruitShop

Nov 4th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FruitShop
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Напишете програма, която чете от конзолата плод(banana / apple / orange / grapefruit /
  14.             //kiwi / pineapple / grapes), ден от седмицата(Monday / Tuesday / Wednesday / Thursday / Friday /
  15.             //Saturday / Sunday) и количество(десетично число) , въведени от потребителя, и пресмята цената
  16.             //според цените от таблиците по-горе.Резултатът да се отпечата закръглен с 2 цифри след десетичната точка.
  17.             //При невалиден ден от седмицата или невалидно име на плод да се отпечата “error”.
  18.  
  19.             string fruit = Console.ReadLine().ToLower();
  20.             string day = Console.ReadLine().ToLower();
  21.             double quantity = double.Parse(Console.ReadLine());
  22.  
  23.             double price = -1.0;
  24.  
  25.             if (day == "monday" || day == "tuesday" || day == "wednesday" || day == "thursday" || day == "friday")
  26.             {
  27.                 switch (fruit)
  28.                 {
  29.                     case "banana":
  30.                         price = 2.50 * quantity;
  31.                         break;
  32.                     case "apple":
  33.                         price = 1.20 * quantity;
  34.                         break;
  35.                     case "orange":
  36.                         price = 0.85 * quantity;
  37.                         break;
  38.                     case "grapefruit":
  39.                         price = 1.45 * quantity;
  40.                         break;
  41.                     case "kiwi":
  42.                         price = 2.70 * quantity;
  43.                         break;
  44.                     case "pineapple":
  45.                         price = 5.50 * quantity;
  46.                         break;
  47.                     case "grapes":
  48.                         price = 3.85 * quantity;
  49.                         break;
  50.                     default:
  51.                         Console.WriteLine("error fruit");
  52.                         break;
  53.                 }
  54.             }
  55.             else if (day == "saturday" || day == "sunday")
  56.             {
  57.                 switch (fruit)
  58.                 {
  59.                     case "banana":
  60.                         price = 2.70 * quantity;
  61.                         break;
  62.                     case "apple":
  63.                         price = 1.25 * quantity;
  64.                         break;
  65.                     case "orange":
  66.                         price = 0.90 * quantity;
  67.                         break;
  68.                     case "grapefruit":
  69.                         price = 1.60 * quantity;
  70.                         break;
  71.                     case "kiwi":
  72.                         price = 3.00 * quantity;
  73.                         break;
  74.                     case "pineapple":
  75.                         price = 5.60 * quantity;
  76.                         break;
  77.                     case "grapes":
  78.                         price = 4.20 * quantity;
  79.                         break;
  80.                     default:
  81.                         Console.WriteLine("error fruit");
  82.                         break;
  83.                 }
  84.             }
  85.             else
  86.             {
  87.                 Console.WriteLine("error day");
  88.             }
  89.  
  90.             if (price > 0)
  91.             {
  92.                 Console.WriteLine("{0:f2} BGN", price);
  93.             }
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment