#include <cs50.h>
#include <stdio.h>
int main(void)
{
int counter = 0;
int apop;
int e;
// TODO: Prompt for start size
do
{
int s;
do
{
s = get_int("Start pop: ");
}
while (s < 9);
// TODO: Prompt for end size
do
{
e = get_int("End pop: ");
}
while (e < s);
// TODO: Calculate number of years until we reach threshold
apop = s + (s / 3 - s / 4);
counter++;
}
while (apop < e);
// TODO: Print number of years
printf("Years = %i\n", counter);
}
1 Answer
The loops that ask for the initial and final numbers are nested inside another DO-WHILE loop, whose end-of-cycle condition is:
while (apop < e);
as long as this condition is not satisfied, the innermost conditions will continue to run.