he population of town Ais less than the population of town B. However, the population of town Ais growing faster than the population of town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs the number of years it will take for the population of town A to become greater than or equal to the population or town B. It also outputs the populations of both towns at that time. Your program should utilize input validation loopsto allow the user to correct errors on input so that the program can continue processing. This program should have two input validation loops: •one to verify that the population of town A is less than the population of town B •one to verify that the population growth rate of town A is greater than the population growth rate o
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
The population of town
Your program should utilize input validation loopsto allow the user to correct errors on input so that the program can continue processing. This program should have two input validation loops:
•one to verify that the population of town A is less than the population of town B
•one to verify that the population growth rate of town A is greater than the population growth rate of town B.
Here is the
Get the initial population of town A and town B.
While the initial population of town A > initial population of town B
Get the initial population of town A and town B
Get the growth rates of town A and town B.
While the growth rate of A < growth rate of B
Get the growth rate of town A and town B
To solve the problem, consider the populations of town A and town B from the initial year to the next year:
•populationA = populationA + populationA * growthRateA
•populationB = populationB + populationB * growthRateB
Set up a loop to compare the new population values to see if populationAis greater than or equal to populationB, if not, repeat the process until it is. Set up a counter inside the loop to determine the number of years it takesfor the populations to match.
C++
Trending now
This is a popular solution!
Step by step
Solved in 2 steps