Advertisement
desislava_topuzakova

04. Clever Lily

Jul 25th, 2022
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.CleverLily
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int age = int.Parse(Console.ReadLine());
  10.             double priceForLaundry = double.Parse(Console.ReadLine());
  11.             int priceForToy = int.Parse(Console.ReadLine());
  12.             int toys = 0;
  13.             int money = 0;
  14.             int evenBirthdays = 0;
  15.             int extraMoney = 0;
  16.  
  17.             for (int countOfBirthdays = 1; countOfBirthdays <= age; countOfBirthdays++)
  18.             {
  19.                 if (countOfBirthdays % 2 == 0)
  20.                 {
  21.                     evenBirthdays++;                  
  22.                     extraMoney += 10;
  23.                     money += extraMoney;
  24.                 }
  25.                 else
  26.                 {
  27.                     toys++;
  28.                 }
  29.             }
  30.  
  31.             int moneyFromToys = toys * priceForToy;
  32.             int finalSum = (money + moneyFromToys) - evenBirthdays;
  33.  
  34.             if (finalSum >= priceForLaundry)
  35.             {
  36.                 double moneyLeft = finalSum - priceForLaundry;
  37.                 Console.WriteLine($"Yes! {moneyLeft:f2}");
  38.             }
  39.             else
  40.             {
  41.                 double moneyNeeded = priceForLaundry - finalSum;
  42.                 Console.WriteLine($"No! {moneyNeeded:f2}");
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement