Created
March 13, 2016 09:12
-
-
Save Kiso-blg/4fb1b027b9c253ab1410 to your computer and use it in GitHub Desktop.
Basics Exam 20 December 2014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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