Advertisement
ralichka

05.More.Exercises.For.Loop-01.Back.to.the.Past

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