Created
February 1, 2021 06:14
-
-
Save jibachhydv/a666aa621b86d2604e584571ba1d475c to your computer and use it in GitHub Desktop.
Population Lab CS50x
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
#include <cs50.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
// Prompt for the start size | |
int startSize; | |
do { | |
startSize = get_int("Start size: "); | |
} while (startSize <= 8); | |
// Prompt for end size | |
int endSize; | |
do { | |
endSize = get_int("End size: "); | |
} while (endSize < startSize); | |
// Calculate number of years until we reach threshold | |
int currentNum = startSize; | |
int numberOfYears = 0; | |
// handling the same size input case | |
if (startSize == endSize){ | |
numberOfYears = 0; | |
} else { | |
do { | |
int born = currentNum / 3; | |
int death = currentNum / 4; | |
currentNum = currentNum + born -death; | |
numberOfYears = numberOfYears + 1; | |
} while (currentNum != endSize && currentNum <= endSize); | |
} | |
// TODO: Print number of years | |
printf("Years: %i\n", numberOfYears); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment