Advertisement
plamen27

Back to the Past fixed 2

Jul 18th, 2016
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 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 _4.BackToThePast
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double heritage = double.Parse(Console.ReadLine());
  14. double yearToLive = double.Parse(Console.ReadLine());
  15. double spend = 0;
  16. double sum1 = 0;
  17. double sum2 = 0;
  18. double yearsold = 17;
  19. double total1 = 0;
  20. double total2 = 0;
  21. for (double year = 1800; year <= yearToLive; year++)
  22. {
  23. if (year % 2 == 0)
  24. {
  25. spend = 12000;
  26. sum1 = sum1 + spend;
  27.  
  28. }
  29. else
  30. {
  31. yearsold += 2;
  32. spend = 12000 + (50 * yearsold);
  33. sum2 = sum2 + spend;
  34.  
  35. }
  36. }
  37.  
  38. double total = heritage - (sum1 + sum2);
  39.  
  40. if (total >= 0)
  41. {
  42. Console.WriteLine("Yes! He will live a carefree life and will have {0:F2} dollars left.", total);
  43. }
  44. else
  45. {
  46. Console.WriteLine("He will need {0:F2} dollars to survive.", Math.Abs(total));
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement