-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpopulation.c
45 lines (39 loc) · 886 Bytes
/
population.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cs50.h>
#include <stdio.h>
int getStartSize(void);
int getEndSize(int);
int main(void)
{
// Get starting population size
int startSize = getStartSize();
// Get ending population size
int endSize = getEndSize(startSize);
// Time taken to go from startSize to endSize
int years = 0;
while (startSize < endSize)
{
startSize = startSize + (startSize / 3) - (startSize / 4);
++years;
}
printf("Years: %d\n", years);
}
int getStartSize(void)
{
int num;
do
{
num = get_int("Start size: ");
}
while (num < 9); // Reject any number less than 9(min start population size limit)
return num;
}
int getEndSize(int startSize)
{
int num;
do
{
num = get_int("End size: ");
}
while (num < startSize); //Reject any number that is less than startSize
return num;
}