Advertisement
IvetValcheva

04. Clever Lily

Jan 31st, 2022
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clever_Lily
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int age = int.Parse(Console.ReadLine());
  10.             double washingMachine = double.Parse(Console.ReadLine());
  11.             int toyPrice = int.Parse(Console.ReadLine());
  12.  
  13.             //когато i e четно => i%2==0
  14.             //                 => (2 -> 10, 4 -> 20, 6 -> 30...и т.н.)
  15.             //                 => сумата, която получава е нейната възраст*5 - 1лв (взет от брат и)
  16.             //                 => i*5-1
  17.  
  18.             //когато i е НЕчетно => i%2!=0 => получава играчка на стойност toyPrice
  19.  
  20.             double money = 0;
  21.  
  22.             for (int i = 1; i <=age; i++)
  23.             {
  24.                 if (i % 2 == 0)
  25.                 {
  26.                     // money = money + i * 5 - 1;
  27.                     money += i * 5 - 1;
  28.                 }
  29.                 else
  30.                 {
  31.                     //money = money + toyPrice;
  32.                     money += toyPrice;
  33.                 }
  34.             }
  35.  
  36.             if (money >= washingMachine)
  37.             {
  38.                 Console.WriteLine($"Yes! {money-washingMachine:f2}");
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine($"No! {washingMachine-money:f2}");
  43.             }
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement