braveheart1989

Piggy_Bank

Mar 11th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 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 _01.Piggy_Bank
  8. {
  9.     class Piggy_Bank
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //•   On the first line you will be given an integer – the price of the tank.
  14.             decimal priceOfTheTank = decimal.Parse(Console.ReadLine());
  15.             //•   On the second line you will be given the number of party days in a month.
  16.             uint partyDays = uint.Parse(Console.ReadLine());
  17.             uint daysInMonth = 30;
  18.             uint normalDays = daysInMonth - partyDays;
  19.             uint normalDaysSaves = normalDays * 2;
  20.             uint partyDaysSpend = partyDays * 5;
  21.             uint averagePerMonth = normalDaysSaves - partyDaysSpend;
  22.             double monthsNeeded = Math.Ceiling((double)priceOfTheTank / averagePerMonth);
  23.  
  24.             double neededYears = Math.Floor(monthsNeeded / 12.0);
  25.  
  26.             double monthsLeft = Math.Ceiling(monthsNeeded % 12);
  27.  
  28.             if (normalDaysSaves > partyDaysSpend)
  29.             {
  30.                 Console.WriteLine("{0} years, {1} months", neededYears, monthsLeft);
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("never");
  35.             }
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment