SHOW:
|
|
- or go back to the newest paste.
1 | //starting off | |
2 | #include <iostream> | |
3 | #include <cmath> | |
4 | using namespace std; | |
5 | ||
6 | int main () | |
7 | { | |
8 | //initializing variables for number of organisms given, average daily population increase, and number of days multiplying | |
9 | double startNumOrganisms; | |
10 | double aveDailyIncrease; | |
11 | double numDaysMult; | |
12 | ||
13 | //asking for the starting number of organisms | |
14 | cout << "Enter the starting number of organisms: "; | |
15 | cin >> startNumOrganisms; | |
16 | ||
17 | // asking for the average daily population increase percentage | |
18 | cout << "Enter the average daily population increase (as a percentage): "; | |
19 | cin >> aveDailyIncrease; | |
20 | ||
21 | // asking for the number of days they will multiply | |
22 | cout << "Enter the number of days they will multiply: "; | |
23 | cin >> numDaysMult; | |
24 | ||
25 | // each day given? yikes. Define "day"? | |
26 | //int day; | |
27 | ||
28 | // defining population size for the population size found on each day | |
29 | //int populationSize; | |
30 | ||
31 | // limiting what I will accept for cin | |
32 | ||
33 | // no startNumOrganisms under 2 | |
34 | // if the bastards cin something wrong anyway, this is what I will display: | |
35 | if (startNumOrganisms <2) | |
36 | { | |
37 | cout << "The starting number of organisms must be at least 2."; | |
38 | cin >> startNumOrganisms; | |
39 | } | |
40 | ||
41 | // no population increase less than 0, also the display | |
42 | if (aveDailyIncrease <0) | |
43 | { | |
44 | cout << "The average daily population increase must be a positive value."; | |
45 | cin >> aveDailyIncrease; | |
46 | } | |
47 | ||
48 | // | |
49 | if (numDaysMult <1) | |
50 | { | |
51 | cout << "The number of days must be at least 1."; | |
52 | cin >> numDaysMult; | |
53 | } | |
54 | ||
55 | // setting up the loop: using FOR loop | |
56 | ||
57 | int populationSize = startNumOrganisms; | |
58 | ||
59 | - | for (double day = 1; day <= numDaysMult ; ++day) |
59 | + | for (int day = 1; day <= numDaysMult ; day++) |
60 | { | |
61 | populationSize += populationSize * aveDailyIncrease; | |
62 | // round number by converting to int | |
63 | - | //int rounded = populationSize; |
63 | + | int rounded = populationSize; |
64 | // displaying the answers for each day | |
65 | - | cout << "On day " << day << " the population size was " << populationSize << ".\n"; |
65 | + | cout << "On day " << day << " the population size was " << rounded << ".\n"; |
66 | } | |
67 | ||
68 | return 0; | |
69 | } |