BubaLazi

TainingHall - Test

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