Advertisement
Guest User

Untitled

a guest
Sep 29th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string fruit = Console.ReadLine();
  9.         string day = Console.ReadLine();
  10.         double quantity = double.Parse(Console.ReadLine());
  11.         bool isValidDay = day == "Monday" || day == "Tuesday" ||
  12.                           day == "Wednesday" || day == "Thursday" ||
  13.                           day == "Friday" || day == "Saturday" ||
  14.                           day == "Sunday";
  15.  
  16.         bool isWeekend = day == "Saturday" || day == "Sunday";
  17.         var fruitPrices = new Dictionary<string, double>()
  18.             {
  19.                 { "banana",isWeekend? 2.70:2.50 },
  20.                 { "apple",isWeekend? 1.25:1.20 },
  21.                 { "orange",isWeekend? 0.90:0.85 },
  22.                 { "grapefruit",isWeekend?1.60 :1.45 },
  23.                 { "kiwi", isWeekend?3.00:2.70 },
  24.                 { "pineapple",isWeekend? 5.60: 5.50},
  25.                 { "grapes",isWeekend?4.20: 3.85 }
  26.             };
  27.  
  28.         if (isValidDay && fruitPrices.ContainsKey(fruit))
  29.         {
  30.             Console.WriteLine((fruitPrices[fruit] * quantity).ToString("F2"));
  31.         }
  32.         else
  33.         {
  34.             Console.WriteLine("error");
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement