Advertisement
dbunalov

04.BackToThePast

Jul 21st, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.BackToThePast
  4. {
  5.     class BackToThePast
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var startAge = 0;
  10.             var heritage = double.Parse(Console.ReadLine());
  11.             var finalYear = int.Parse(Console.ReadLine());
  12.             var moneyLeft = 0.0;
  13.             var spentMoney = 0.00;//money spended per year
  14.  
  15.             for (int i = 1800; i <= finalYear; i++)//calc money and Ivanchos age
  16.             {
  17.                 startAge = (i + 18) - 1800;// counting Ivanchos age
  18.                 if (i % 2 == 0)//calc money
  19.                 {
  20.                     spentMoney += 12000.0;
  21.                     moneyLeft = heritage - spentMoney;
  22.                 }
  23.                 else if (i % 2 != 0)
  24.                 {
  25.                     spentMoney += 12000.0 + (50 * startAge);
  26.                     moneyLeft = heritage - spentMoney;
  27.                 }
  28.             }
  29.             if (moneyLeft >= 0)
  30.             {
  31.                 Console.WriteLine("Yes! He will live a carefree life and will have {0:0.00} dollars left.", moneyLeft);
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("He will need {0:0.00} dollars to survive.", Math.Abs(moneyLeft));
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement