using loops in C++ 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. Prompts, Output Labels and Messages .The three input data should be prompted for with the following prompts: "Enter the starting number of organisms: ", "Enter the average daily population increase (as a percentage): , and "Enter the number of days they will multiply: " respectively. The population sizes displayed should appear on separate lines, each of the form "On day D the population size was P." where D is the day number (starting with 1) and P is the population you calculated for that day. Input Validation.Do not accept a number less than 2 for the starting size of the population. If the user fails to satisfy this print a line with this message "The starting number of organisms must be at least 2.", display the prompt again and try to read the value . Similarly, do not accept a negative number for average daily population increase , using the message "The average daily population increase must be a positive value ." and retrying. Finally, do not accept a number less than 1 for the number of days they will multiply and use the message "The number of days must be at least 1."
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
using loops in C++
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.
Prompts, Output Labels and Messages .The three input data should be prompted for with the following prompts: "Enter the starting number of organisms: ", "Enter the average daily population increase (as a percentage): , and "Enter the number of days they will multiply: " respectively. The population sizes displayed should appear on separate lines, each of the form "On day D the population size was P." where D is the day number (starting with 1) and P is the population you calculated for that day.
Input Validation.Do not accept a number less than 2 for the starting size of the population. If the user fails to satisfy this print a line with this message "The starting number of organisms must be at least 2.", display the prompt again and try to read the value . Similarly, do not accept a negative number for average daily population increase , using the message "The average daily population increase must be a positive value ." and retrying. Finally, do not accept a number less than 1 for the number of days they will multiply and use the message "The number of days must be at least 1."
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images