Advertisement
YavorGrancharov

Training_Hall_Equipment

Jun 7th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.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 Training_Hall_Equipment
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double budget = double.Parse(Console.ReadLine());
  14.             int count = int.Parse(Console.ReadLine());
  15.  
  16.             double realPrice = 0.00;
  17.  
  18.             if (count >= 0 && count <= 10)
  19.             {
  20.                 for (int i = 0; i < count; i++)
  21.                 {
  22.                     String item = Console.ReadLine();
  23.                     double price = double.Parse(Console.ReadLine());
  24.                     int itemCount = int.Parse(Console.ReadLine());
  25.  
  26.                     realPrice += price * itemCount;
  27.  
  28.                     if (budget >= realPrice)
  29.                     {
  30.                         Console.WriteLine(
  31.                             itemCount != 1 ?
  32.                             $"Adding {itemCount} {item}s to cart." :
  33.                             $"Adding {itemCount} {item} to cart.");
  34.                     }
  35.                     else
  36.                     {
  37.                         Console.WriteLine(itemCount != 1 ?
  38.                             $"Adding {itemCount} {item}s to cart." :
  39.                             $"Adding {itemCount} {item} to cart.");
  40.                     }
  41.                 }
  42.                 Console.WriteLine($"Subtotal: ${realPrice:F2}");
  43.  
  44.                 Console.WriteLine(budget >= realPrice ?
  45.                     $"Money left: ${Math.Abs(budget - realPrice):F2}" :
  46.                     $"Not enough. We need ${Math.Abs(realPrice - budget):F2} more.");
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement