-
Notifications
You must be signed in to change notification settings - Fork 0
/
population.c
39 lines (32 loc) · 1.08 KB
/
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
#include <stdio.h>
// ANSI escape sequences to color output
const char *red = "\033[31m";
const char *green = "\033[32m";
const char *blue = "\033[34m";
const char *reset = "\033[0m";
int main(void) {
float start, end;
int years = 0;
// Prompt the user for a starting # o'llamas
do {
printf("Initial # of llamas: ");
scanf("%f", &start);
} while (start < 9.0); // Re-Prompt if input is less than 9;
// Prompt the user for an ending # o'llamas
do {
printf("Desired # of llamas: ");
scanf("%f", &end);
} while ( end <= start );
// How many years will it take to get to the goal?
// Every year, 1/3 of our curent llamas are born; 1/4 passes away;
// { Common denominator of 1/3 & 1/4 = 1/12 new llamas per year }
while ((int)start < (int)end) {
start += start / 12.0;
years++;
}
printf(
"Starting with %s%i llamas%s\nit will take %s%i year(s)%s\nto reach a population of %s%i llamas%s\n",
green, (int)start, reset, red, years, reset, blue, (int)end, reset
);
return 0;
}