LardaX

Back_to_the_Past

Aug 26th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 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 moneyHeritage = double.Parse(Console.ReadLine());
  14.             int year = int.Parse(Console.ReadLine());
  15.             double moneySpent = 0.0;
  16.  
  17.             for (int i = 1800; i <= year; i++)
  18.             {
  19.                 if (i % 2 == 0)
  20.                 {
  21.                     moneySpent += 12000;
  22.                 }
  23.                 else
  24.                 {
  25.                     moneySpent += 12000 + 50 * (i - 1800 + 18);
  26.                 }
  27.             }
  28.             if (moneyHeritage >= moneySpent)
  29.             {
  30.                 Console.WriteLine("Yes! He will live a carefree life and will have {0:f2} dollars left.", moneyHeritage - moneySpent);
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("He will need {0:f2} dollars to survive.", moneySpent - moneyHeritage);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment