Toy Store - Programming Basics
Привет,
Понеже се измъчих доста с тази задача, след решението ѝ от моя страна, исках да споделя кодът, който Judge сметна за верен с вас:
Постарах се да го подредя, така че, ако изпитвате затрудения със задачата, заповядайте:
using System;
namespace Toy Store
{
class Program
{
static void Main(string[] args)
{
// vacation price
double vacationPrice = double.Parse(Console.ReadLine());
//toy amount
double puzzleCount = double.Parse(Console.ReadLine());
double dollCount = double.Parse(Console.ReadLine());
double teddyBearCount = double.Parse(Console.ReadLine());
double minionCount = double.Parse(Console.ReadLine());
double truckCount = double.Parse(Console.ReadLine());
double toyCount = puzzleCount + dollCount + teddyBearCount + minionCount + truckCount; //total amount
//toy prices
double puzzlePrice = 2.60;
double dollPrice = 3;
double teddyBearPrice = 4.10;
double minionPrice = 8.20;
double truckPrice = 2.00;
// toy profits
double puzzleProfit = puzzleCount * puzzlePrice;
double dollProfit = dollCount * dollPrice;
double teddyBearProfit = teddyBearCount * teddyBearPrice;
double minionProfit = minionCount * minionPrice;
double truckProfit = truckCount * truckPrice;
double toyProfit = puzzleProfit + dollProfit + teddyBearProfit + minionProfit + truckProfit; //total amount of money
if (toyCount >= 50)
{
double discountPrice = toyProfit - toyProfit * 0.25;
double priceAfterRent = discountPrice - discountPrice * 0.10;
if (priceAfterRent >= vacationPrice)
{
double money = priceAfterRent - vacationPrice;
Console.WriteLine($"Yes! {money:F2} lv left.");
}
else
{
double money = vacationPrice - priceAfterRent;
Console.WriteLine($"Not enough money! {money:F2} lv needed.");
}
}
else
{
double priceAfterRent = toyProfit - toyProfit * 0.10;
if (priceAfterRent >= vacationPrice)
{
double money = priceAfterRent - vacationPrice;
Console.WriteLine($"Yes! {money:F2} lv left.");
}
else
{
double money = vacationPrice - priceAfterRent;
Console.WriteLine($"Not enough money! {money:F2} lv needed.");
}
}
}
}
}
Благодаря!