Задача на проценты codewars
Задача:
In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
Примеры:
nb_year(1500, 5, 100, 5000) -> 15
nb_year(1500000, 2.5, 10000, 2000000) -> 10
мой код которые работает неверное и в том месте где я привожу к int
private static int NbYear(int p0, double percent, int aug, int p)
{
int totalNumberOfYears = 0;
while (p0 <= p)
{
p0 = p0 + p0 * (((int)percent) / 100) + aug;
totalNumberOfYears++;
}
return totalNumberOfYears;
}
Проблема: Неверно считает количество лет, и как я понял ошибка в первой строке тела цикла, там произведение p0 на (((int)percent) / 100) получается 0, я пробовал убрать привидение типов и вместо 100 брал 100.0, но тоже не помогло, помогите пожалуйста
Источник: Stack Overflow на русском