Advertisement
Terziyski

Training Hall Equipment

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