Advertisement
fk4m1913

Untitled

Apr 8th, 2020
274
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 BackToThePast
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //input money inherited and last year
  10.             //ivancho age = 18
  11.             //ivancho startyear = 1800 / 18 years old
  12.             //if year % 2 == 0 ivancho spends 12000
  13.             //else if year % 2 == ivancho spends 12000 + 50 * ivancho age
  14.             //sum money spend for the years
  15.             //will the money be enough
  16.             //output
  17.  
  18.             double moneyInherited = double.Parse(Console.ReadLine());
  19.             int lastYear = int.Parse(Console.ReadLine());
  20.  
  21.             int ivanchoAge = 18;
  22.             double moneySpend = 0;
  23.  
  24.             for (int i = 1800; i <= lastYear; i++)
  25.             {
  26.                 if (i % 2 == 0)
  27.                 {
  28.                     moneySpend += 12000;
  29.                 }
  30.                 else if (i % 2 == 1)
  31.                 {
  32.                     moneySpend += 12000 + 50 * ivanchoAge;
  33.                 }
  34.  
  35.                 ivanchoAge += 1;
  36.             }
  37.  
  38.             if (moneyInherited >= moneySpend)
  39.             {
  40.                 Console.WriteLine($"Yes! He will live a carefree life and will have {moneyInherited - moneySpend:f2} dollars left.");
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine($"He will need {moneySpend - moneyInherited:f2} dollars to survive.");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement