Answer:
Following are the program in the C++ Programming Language:
#include <iostream>
using namespace std;
int main() {
float starting, average;
int num;
std::cout <<"Enter starting number of the organisms: ";
while(!(std::cin >> starting)|| starting < 2){
std::cout<<"starting number must be greater than 2\n";
std::cout <<"Enter starting number of the organisms: ";
std::cin.clear();
std::cin.ignore(123,'\n');
}
std::cout <<"Enter the average of daily population is increase %: ";
while(!(std::cin >> average)|| average < 0){
std::cout<<"Average must be greater than 0\n Enter average";
std::cin.clear();
std::cin.ignore(123,'\n');
}
average *= .01;
std::cout <<"Enter the number of days: ";
while(!(std::cin >> num)|| num < 1){
std::cout<<"Number of days no be less than 1\n" <<"Enterthe number of days\n";
std::cin.clear();
std::cin.ignore(123,'\n');
}
for(int i=0; i<num; i++){
std::cout<<"population size of day"<<(i+1);
std::cout<<": "<<starting<<std::endl;
starting +=(starting*average);
}
return 0;
}
<u>Output</u>:
Enter starting number of the organisms: 4
Enter the average of daily population is increase %: 5
Enter the number of days: 4
population size of day1: 4
population size of day2: 4.2
population size of day3: 4.41
population size of day4: 4.6305
Explanation:
Here, we define header file "<iostream>" and namespace "std".
- Then, we define the main() inside it, we set two float data type variable i.e., "starting", "average" and set an integer data type variable i.e., "num".
- Then, we print a message and after that, we set the while loop for get input from the user in variable "starting" and pass the condition inside loop we print message than clear cin and ignore 123 then, we again do this to get input from user in variable "average".
- Then, we set the for loop and pass the condition inside the loop print the size of the day then print the value of "starting" after that we multiply.
- Finally, we return 0 and close the main function.