MiroslavKisov

Back_To_The_Past

Jul 28th, 2017
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Back_To_The_Past
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double moneyInherited = double.Parse(Console.ReadLine());
  14.             int yearToSurvive = int.Parse(Console.ReadLine());
  15.             int startYear = 1800;
  16.             int yearsToLive = yearToSurvive - startYear;
  17.             int yearsOfAge = 18;
  18.             for(int i = 0;i<=yearsToLive;i++)
  19.             {
  20.                 if (startYear % 2 == 0)
  21.                 {
  22.                     moneyInherited = moneyInherited - 12000;
  23.                     startYear++;
  24.                     yearsOfAge++;
  25.                 }
  26.                 else if (startYear % 2 != 0)
  27.                 {
  28.                     moneyInherited = moneyInherited - (12000 + 50 * yearsOfAge);
  29.                     startYear++;
  30.                     yearsOfAge++;
  31.                 }
  32.             }
  33.             if(moneyInherited>=0)
  34.             {
  35.                 Console.WriteLine($"Yes! He will live a carefree life and will have {moneyInherited:f2} dollars left.");
  36.             }
  37.             else
  38.             {
  39.                 moneyInherited = Math.Abs(moneyInherited);
  40.                 Console.WriteLine($"He will need {moneyInherited:f2} dollars to survive.");
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment