#include <cs50.h>
#include <stdio.h>
int main(void)
{
int start, end, years = 0;
// Prompt for start size
do
{
start = get_int("Start size: ");
}
while (start < 9);
// Prompt for end size
do
{
end = get_int("End size: ");
}
while (end < start);
//Calculating the number of years
while (start < end)
{
start += (start / 2);
years++;
}
printf("Years: %i\n", years);
}
output:
$ ./population
Start size: 1200
End size: 1300
Years: 1
$ ./population
Start size: -5
Start size: 3
Start size: 9
End size: 5
End size: 18
Years: 8
$ ./population
Start size: 20
End size: 1
End size: 10
End size: 100
Years: 20
$ ./population
Start size: 100
End size: 1000000
Years: 115