Question: 17. Population Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number
| 17. Population Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage of current population), and the number of days they will multiply. A loop should display the size of the population for each day. Input Validation: The program should not accept a number less than 2 for the starting size of the population, a negative number for average daily population increase, or a number less than 1 for the number of days they will multiply. In addition to the book specs, include the following data validation loops: Starting number of organisms - must be numeric and >= 2. daily population increase - must be > 0 (do not check for non-numeric) number of days - must be >= 1 (do not check for non-numeric) |
The program requires you to code loops.
Use loops for the data validation. You may use do-while or while loops. (These links take you to other parts of the current document)
Complete the "for" loop structure to print out 1 line for each day with start and end population
Population should not be displayed with values after the decimal point. It should be displayed as an integer.
Print out population at the start and end of each day.
Refer to the Programming Standards document and follow the rules stated there in order
#include#include using namespace std; //container for preprocessor directives I NEED TO USE THIS CODE PLEASE DO IT WITH THIS CODE THANKS int main() { int growth, days, count; int population = 0, startPop; cout << "Enter starting population: "; cin >> startPop; /* Code the data validation loop to ensure that startPop is a number greater than 2 */ do { cout << "Enter daily growth % (.1 must be entered as 10. No decimals!): "; cin >> growth; }while (growth < 0); cout << "Enter number of days to calculate: "; cin >> days; while (days < 1) { cout << "Invalid. "; cout << " Enter number of days to calculate: "; cin >> days; } cout << "-----------------------------------------------------------" << endl << endl; cout << "Start Population: " << startPop << endl << "Daily Percent Growth: " << growth << "%" << endl << "Number of Days: " << days << endl << endl; cout << "Day" << '\t' << "Population" << '\t' << "Population" << endl << '\t' << "at day start" << '\t' << "at day end" << endl << "------------------------------------------------------" << endl; for (count = 1; count < (days + 1); count++) { cout << count << '\t' << setprecision(0)<< fixed ; /* Write down code to print out start population and end population for the day */ } return 0; }
Sample output from my implementation of the Lab
User input is shown in bold blue lettering highlighted in yellow:
| Enter starting population: kljf Invalid. Input must be numeric. Enter starting population: -100 Invalid. Population must be 2 or greater. Enter starting population: 1 Invalid. Population must be 2 or greater. Enter starting population: 123 Enter daily growth % (.1 must be entered as 10. No decimals!): 12 Enter number of days to calculate: 6 ----------------------------------------------------------- Start Population: 123 Daily Percent Growth: 12% Number of Days: 6 Day Population Population at day start at day end ------------------------------------------------------ 1 123 137 2 137 153 3 153 171 4 171 191 5 191 213 6 213 238 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
