Advertisement
kalitarix

Training hall equipment

May 20th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TrainingHallEquipment
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double budget = double.Parse(Console.ReadLine());
  10.             int numberOfItems = int.Parse(Console.ReadLine());
  11.  
  12.             double totalSum = 0;
  13.  
  14.             for (int items = 1; items <= numberOfItems; items++)
  15.             {
  16.                 string itemName = Console.ReadLine();
  17.                 double price = double.Parse(Console.ReadLine());
  18.                 int countOfItems = int.Parse(Console.ReadLine());
  19.  
  20.                 if (countOfItems > 1)
  21.                 {
  22.                     itemName += "s";
  23.                 }
  24.  
  25.                 Console.WriteLine($"Adding {countOfItems} {itemName} to cart.");
  26.  
  27.                 totalSum += price * countOfItems;
  28.             }
  29.  
  30.             Console.WriteLine($"Subtotal: ${totalSum}");
  31.  
  32.             double difference = Math.Abs(budget - totalSum);
  33.  
  34.             if (budget >= totalSum)
  35.             {
  36.                 Console.WriteLine($"Money left: ${difference:f2}");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine($"Not enough. We need ${difference:f2} more.");
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement