Advertisement
Kriss_7777

Vidin_Prep_Exam_BackToThePast

Dec 1st, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 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_02
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // define and read input variables ................................
  14.             double money = double.Parse(Console.ReadLine());
  15.             int     year = int.Parse(Console.ReadLine());
  16.  
  17.             // define and calc calculated variables ...........................
  18.             int     startYear        = 1800;
  19.             double  moneyEvenYear    = 0.00;
  20.             double  moneyOddYear     = 0.00;
  21.             double  moneyLeft        = 0.00;
  22.  
  23.             // LOGIC nad CALC =================================================
  24.             // calc even and odd money.........................................
  25.             for( int i = startYear; i <= year; i++)
  26.             {
  27.                 if(i % 2 == 0) // even year
  28.                 {
  29.                     moneyEvenYear = moneyEvenYear + 12000;
  30.                 }
  31.                 else // odd year
  32.                 {
  33.                     moneyOddYear = moneyOddYear + 12000 + (50 * (18 + i - startYear));
  34.                 }
  35.             }
  36.  
  37.             moneyLeft = (money - ( moneyEvenYear + moneyOddYear ));
  38.  
  39.             // calc money left ................................................
  40.             if (moneyLeft > 0)
  41.             {
  42.                 Console.WriteLine($"Yes! He will live a carefree life and will have {moneyLeft:f2} dollars left.");
  43.             }
  44.             else
  45.             {
  46.                 Console.WriteLine($"He will need {Math.Abs(moneyLeft):f2} dollars to survive.");
  47.             }
  48.  
  49.  
  50.  
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement