Write a program displays each year population


Problem:

Question- Write a C++ program which calculates and displays each year's population of egrets based of some user input and the following formula:

NextYr = Rate ? CurrentYr ? (1 ? CurrentYr) 1000000

where CurrentYr is the current egret population, NextYr is the population one year later, and Rate can be thought of as the “growth rate” and can have a value between 0 and 4.

Requirements:

a. The program must read input from the user for the initial value of CurrentYr. Valid input for this value is an integer greater than 0 and less than 1000000.

b.  The program must read input from the user for the value of Rate. Valid input for this value is a real number greater than 0 and less than 4.

c. For each of the values which the user must enter (CurrentYr and Rate), if any invalid input (including negative numbers) is entered, then a message informing the user of the valid ranges must be displayed and the user be given a second chance to enter the number. If invalid input is entered on the second chance then the program must terminate with a message that the input can’t be used and without doing any population change calculations.

d. The program is only required to work if an integer is entered by the user for CurrentYr and a numeric value is entered for Rate – i.e. you can assume that the correct type of input is obtained although you must check whether or not it is in the valid range.

e. The program must display the initial population entered by the user (as year 0), followed by the population for each of the next 25 years found by applying the formula above, in the format shown in the sample run below.

f.  If the calculated value for NextYr includes a fractional part, the fractional part must be dropped.

g. The numbers must be right-aligned in their columns as shown in the sample run.

 

Please write the code that calculates and displays each year's population.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a program displays each year population
Reference No:- TGS0892866

Expected delivery within 24 Hours