simonradev

BackToThePast

Mar 12th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 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 BackToThePast
  8. {
  9.     class BackToThePast
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double heritage = double.Parse(Console.ReadLine());
  14.             int yearToLiveTo = int.Parse(Console.ReadLine());
  15.  
  16.             int currAge = 18;
  17.             double moneySpent = 0.0;
  18.             for (int currYear = 1800; currYear <= yearToLiveTo; currYear++)
  19.             {
  20.                 if (currYear % 2 == 0)
  21.                 {
  22.                     //12 000
  23.                     moneySpent += 12000;
  24.                 }
  25.                 else if (currYear % 2 == 1)
  26.                 {
  27.                     //12 000 + (50 * currAge)
  28.                     moneySpent += 12000 + (50 * currAge);
  29.                 }
  30.  
  31.                 currAge++;
  32.             }
  33.  
  34.             if (heritage >= moneySpent)
  35.             {
  36.                 Console.WriteLine($"Yes! He will live a carefree life and will have {(heritage - moneySpent):f2} dollars left.");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine($"He will need {(moneySpent - heritage):f2} dollars to survive.");
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment