IordanRujinov

SmallShop - nested if

Nov 4th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 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 SmallShop
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Напишете програма, която чете град(низ), продукт(низ) и количество(десетично число),
  14.             //въведени от потребителя, и пресмята и отпечатва колко струва съответното количество
  15.             //от избрания продукт в посочения град.
  16.  
  17.             string product = Console.ReadLine().ToLower();
  18.             string town = Console.ReadLine();
  19.             double quantity = double.Parse(Console.ReadLine());
  20.  
  21.             double price = -1.0;
  22.  
  23.             if (town == "Sofia")
  24.             {
  25.                 if (product == "coffee")
  26.                 {
  27.                     price = 0.50 * quantity;
  28.                 }
  29.                 else if (product == "water")
  30.                 {
  31.                     price = 0.80 * quantity;
  32.                 }
  33.                 else if (product == "beer")
  34.                 {
  35.                     price = 1.20 * quantity;
  36.                 }
  37.                 else if (product == "sweets")
  38.                 {
  39.                     price = 1.45 * quantity;
  40.                 }
  41.                 else if (product == "peanuts")
  42.                 {
  43.                     price = 1.60 * quantity;
  44.                 }
  45.             }
  46.             else if (town == "Plovdiv")
  47.             {
  48.                 if (product == "coffee")
  49.                 {
  50.                     price = 0.40 * quantity;
  51.                 }
  52.                 else if (product == "water")
  53.                 {
  54.                     price = 0.70 * quantity;
  55.                 }
  56.                 else if (product == "beer")
  57.                 {
  58.                     price = 1.15 * quantity;
  59.                 }
  60.                 else if (product == "sweets")
  61.                 {
  62.                     price = 1.30 * quantity;
  63.                 }
  64.                 else if (product == "peanuts")
  65.                 {
  66.                     price = 1.50 * quantity;
  67.                 }
  68.             }
  69.             else if (town == "Varna")
  70.             {
  71.                 if (product == "coffee")
  72.                 {
  73.                     price = 0.45 * quantity;
  74.                 }
  75.                 else if (product == "water")
  76.                 {
  77.                     price = 0.70 * quantity;
  78.                 }
  79.                 else if (product == "beer")
  80.                 {
  81.                     price = 1.10 * quantity;
  82.                 }
  83.                 else if (product == "sweets")
  84.                 {
  85.                     price = 1.35 * quantity;
  86.                 }
  87.                 else if (product == "peanuts")
  88.                 {
  89.                     price = 1.55 * quantity;
  90.                 }
  91.             }
  92.             if (price > 0)
  93.             {
  94.                 Console.WriteLine(price);
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment