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*), and the number of days they will multiply. A loop should display the size of the population for each day.
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*), and the number of days they will multiply. A loop should display the size of the population for each day.
In addition to passing the Mimir test cases know that I will view your code to ensure you have the correct functions and that your code writes to a file.
Your code should include the following functions
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//declaration of the required variable
int population, days;
double increase;
//scan the starting population
cout << "Please enter the starting population:";
cin >> population;
while(population < 2){
cout << "You have entered less value!,Please enter the starting population greater than 2: ";
cin >> population;
}
cout << "\n Percentage of increase in the population: ";
cin >> increase;
while(increase < 0){
cout << "You have entered incorrect value, Please enter the positive value: ";
cin >> increase;
}
cout << "\n Enter number of days: ";
cin >> days;
while(days < 1){
cout << "You have entered less than 1, please enter the value greater than 1:";
cin >> days;
}
//Calculation of population for each day
cout << "\nDay\t\tPopulation";
cout << "\n-------------------------\n";
for(int i = 1; i <= days; i++){
population = population * (1 + increase / 100.0);
cout << i << "\t\t" << population << endl;
}
return 0;
}
Comments
Leave a comment