Question

Write a program that will predict the size of a population of organisms. The program should ask t...

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.
Input Validation:
Do not accept a number less than 2 for the starting size of the population. "The starting number of organisms must be at least 2."
Do not accept a negative number for average daily population increase. "The average daily population increase must be a positive value."
Do not accept a number less than 1 for the number of days they will multiply. "The number of days must be at least 1."

Using the following test data:
-1, 1, 3, 25, 12

Your output should look like this:
Enter the starting number of organisms: The starting number of organisms must be at least 2.
Enter the starting number of organisms: The starting number of organisms must be at least 2.

Enter the starting number of organisms: Enter the average daily population increase (as a percentage):

Enter the number of days they will multiply:

On day 1 the population size was 4.
On day 2 the population size was 5.
On day 3 the population size was 6.
On day 4 the population size was 7.
On day 5 the population size was 9.
On day 6 the population size was 11.
On day 7 the population size was 14.
On day 8 the population size was 18.
On day 9 the population size was 22.
On day 10 the population size was 28.
On day 11 the population size was 35.
On day 12 the population size was 44.

This is C++ and let code can be works on visual studio 2017 please.

Use blank lines to separate the major parts of your main function. And show your output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Plzzzzzzzzzzzzzzzzzzzzz Upvote...
Comment for any queries..



Visual C++ Copyable Code :

#include <iostream>
using namespace std;

int main()
{
   int Days, SizeOfPop;
   double DailyIncrease;
   cout << "Enter the starting number of organisms: (The starting number of organisms must be at least 2.) : ";
   cin >> SizeOfPop;
   cout << "Enter the average daily population increase (as a percentage): ";
   cin >> DailyIncrease;
   cout << "Enter the number of days they will multiply: ";
   cin >> Days;


   while (SizeOfPop < 2 || DailyIncrease < 0 || Days < 1)
   {
       if (SizeOfPop < 2)
       {
           cout << "Error!\nStarting size of population " << "must be greater than 2.\n";
           cout << "What is the starting number of organisms? ";
           cin >> SizeOfPop;
       }
       else if (DailyIncrease < 0)
       {
           cout << "Error!\nAverage daily population " << "increase must be greater than 0.\n";
           cout << "What is the average daily population increase? \n" << "(as a percentage of current population)? ";
           cin >> DailyIncrease;
       }
       else if (Days < 1)
       {
           cout << "Error!\nNumber of days must be greater than 0.\n-5";
           cout << "Enter the number of days of growth: ";
           cin >> Days;
       }
   }


//Logic for calculating the increase in population
   for (int X = 1; X <= Days; X++)
   {
       SizeOfPop = SizeOfPop + (DailyIncrease*SizeOfPop);
       cout << "On day " << X << " the population size was " << SizeOfPop << endl;
   }



   system("pause");
   return 0;
}



Sample Output in Visual Studio 2017 :


Enter the starting number of organisms: (The starting number of organisms must be at least 2.) : 2 Enter the average daily po


Enter the starting number of organisms: (The starting number of organisms must be at least 2.) : 1 Enter the average daily po

Add a comment
Know the answer?
Add Answer to:
Write a program that will predict the size of a population of organisms. The program should ask t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5.11: Population Write a program that will predict the size of a population of organisms. The...

    5.11: 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, expressed as a fraction in decimal form: for example 0.052 would mean a 5.2% increase each day), and the number of days they will multiply. A loop should display the size of the population for each day. Input Validation.Do not accept a number less than...

  • Write a program that will predict the size of a population of organisms. The program should...

    Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to display the size of the population for each...

  • Starting out with Python 4th edition I need help with while loops I can't even get...

    Starting out with Python 4th edition I need help with while loops I can't even get one started correctly. Write a program a program that predicts the approximate size of a population of organisms. Problem 4.13 – population Use a while loop; there are no text boxes, just regular input statements Enter number of organisms: 2 Enter average daily increase: 30 Enter number of days to multiply: 10 DAY       APPROXIMATE POPULATION ------------------------------------------------- 1            2 2            2.600 3            3.380 4            4.394...

  • 1.Given an int variable n that has been initialized to a positive value and, in addition,...

    1.Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a for loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.(c++) 2.Given an int variable...

  • In C++ Transient Population Populations are effected by the birth and death rate, as well as...

    In C++ Transient Population Populations are effected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size...

  • In Java. Use the concept of LOOPS: 2.Write a program that calculates the amount a person...

    In Java. Use the concept of LOOPS: 2.Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the...

  • P3.4 Population. In a population, the birth rate is the percentage increase of the population due...

    P3.4 Population. In a population, the birth rate is the percentage increase of the population due to births, and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size of a population The annual birth rate The annual death rate The number of years to display Write a function that calculates...

  • In C++ Write a program that calculates the occupancy rate for a hotel. The program should...

    In C++ Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A loop should then iterate once for each floor. In each iteration, the loop should ask the user for the number of rooms on the floor and how many of them are occupied. After all iterations, the program should display how many room the hotel has, how many of them are occupied, how...

  • Show Me The Money. (15 points) Write a C++ program that calculates how much a person...

    Show Me The Money. (15 points) Write a C++ program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on, with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was...

  • Write a Java program that calculates how much a person would earn after a period of...

    Write a Java program that calculates how much a person would earn after a period of time, according to the following rules: 1. The starting salary for the first day is $1. 2. The salary will double each day. Ask the user to input the number of days worked. The output should display how much the salary was for each day worked, and show the total pay at the end of the work period. Get output similar to the sample...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT