Skip to content

Instantly share code, notes, and snippets.

@Kiso-blg
Created March 13, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiso-blg/4fb1b027b9c253ab1410 to your computer and use it in GitHub Desktop.
Save Kiso-blg/4fb1b027b9c253ab1410 to your computer and use it in GitHub Desktop.
Basics Exam 20 December 2014
using System;
namespace Problem_1___Piggy_Bank
{
class PiggyBank
{
static void Main(string[] args)
{
int tankPrice = int.Parse(Console.ReadLine());
int partiesPerMonth = int.Parse(Console.ReadLine());
int savedMoney = (30 - partiesPerMonth) * 2;
int spendMoney = partiesPerMonth * 5;
bool isSaving = savedMoney > spendMoney;
if (isSaving)
{
double monthsNeed = tankPrice / (double)(savedMoney - spendMoney);
int years = (int)monthsNeed / 12;
double months = Math.Ceiling(monthsNeed % 12);
if (months >= 12)
{
months -= 12;
years++;
}
Console.WriteLine("{0} years, {1} months", years, months);
}
else
{
Console.WriteLine("never");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment