/
P07_TrainingHallEquipment.cs
33 lines (28 loc) · 1.05 KB
/
P07_TrainingHallEquipment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
namespace P07_TrainingHallEquipment
{
class P07_TrainingHallEquipment
{
static void Main(string[] args)
{
double budget = double.Parse(Console.ReadLine());
int itemsCount = int.Parse(Console.ReadLine());
double subtotal = 0;
for (int i = 0; i < itemsCount; i++)
{
string productName = Console.ReadLine();
double productPrice = double.Parse(Console.ReadLine());
int productCount = int.Parse(Console.ReadLine());
productName += productCount > 1 ? "s" : "";
Console.WriteLine($"Adding {productCount} {productName} to cart.");
subtotal += (productPrice * productCount);
}
Console.WriteLine($"Subtotal: ${subtotal:F2}");
Console.WriteLine(
budget >= subtotal ?
$"Money left: ${budget - subtotal:F2}" :
$"Not enough. We need ${subtotal - budget:F2} more."
);
}
}
}