Advertisement
Niicksana

Back To The Past

Dec 9th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 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.             // Exam - 17 July 2016  100/100
  14.             double inheritance = double.Parse(Console.ReadLine());
  15.             int year = int.Parse(Console.ReadLine());
  16.  
  17.             int ageBoy = 18;
  18.  
  19.             double moneyNeeded = 0;
  20.  
  21.             for (int years = 1800; years <= year; years ++)
  22.             {
  23.                 if (years % 2 == 0)
  24.                 {
  25.                     moneyNeeded += 12000;
  26.                     ageBoy++;
  27.                 }
  28.  
  29.                 else
  30.                 {
  31.                     moneyNeeded += (12000 + (ageBoy * 50));
  32.                     ageBoy++;
  33.                 }
  34.             }
  35.  
  36.             if (moneyNeeded <= inheritance)
  37.             {
  38.                 Console.WriteLine("Yes! He will live a carefree life and will have {0:f2} dollars left.", inheritance - moneyNeeded);
  39.             }
  40.  
  41.             else
  42.             {
  43.                 Console.WriteLine("He will need {0:f2} dollars to survive.", moneyNeeded - inheritance);
  44.             }
  45.  
  46.             // Variaat 2 - 90/100  
  47.             double leftInheritance = inheritance;
  48.  
  49.             for (int years = 1800; years <= year; years ++)
  50.             {
  51.                 if (years % 2 == 0)
  52.                 {
  53.                     leftInheritance -= 12000;
  54.                     ageBoy++;
  55.                 }
  56.  
  57.                 else
  58.                 {
  59.                     leftInheritance = leftInheritance - (12000 + (ageBoy * 50));
  60.                     ageBoy++;
  61.                 }
  62.             }
  63.  
  64.             if (leftInheritance > 0)
  65.             {
  66.                 Console.WriteLine("Yes! He will live a carefree life and will have {0:f2} dollars left.", leftInheritance);
  67.             }
  68.  
  69.             else
  70.             {
  71.                 Console.WriteLine("He will need {0:f2} dollars to survive.", Math.Abs(leftInheritance));
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement