fbinnzhivko

01.01 Piggy Bank

Mar 12th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. class PiggyBank
  3. {
  4.     static void Main()
  5.     {
  6.         int tankPrice = int.Parse(Console.ReadLine());
  7.         int numberOfPartyDays = int.Parse(Console.ReadLine());
  8.  
  9.         int savingsDays = 30 - numberOfPartyDays;
  10.         int lostManyOfMonth = 5 * numberOfPartyDays;
  11.         int savedManyOfMonth = 2 * savingsDays;
  12.         int totalSavedManyOfMont = (savedManyOfMonth - lostManyOfMonth);
  13.         double totalSavedMonth = (double)tankPrice / totalSavedManyOfMont;
  14.         int requiredYears = (int)totalSavedMonth / 12;
  15.         double montsOver = (double)totalSavedMonth % 12;
  16.         int requiredMonts = (int)Math.Ceiling(montsOver);
  17.  
  18.  
  19.  
  20.         if (requiredMonts == 12)
  21.         {
  22.             requiredYears = requiredYears + 1;
  23.             requiredMonts = 0;
  24.         }
  25.         if (totalSavedManyOfMont < 0)
  26.         {
  27.             Console.WriteLine("never");
  28.         }
  29.         else
  30.         {
  31.             Console.WriteLine("{0} years, {1} months", requiredYears, requiredMonts);
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment