Answer to Question #171704 in C++ for Anonymous

Question #171704

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

  •  function to get value for the starting number organisms
  •  function to get a valid value for the average daily
  •  function to get a valid value for the number of days



 



1
Expert's answer
2021-03-16T12:51:30-0400
#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;
 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS