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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 8PE
icon
Related questions
icon
Concept explainers
Question

The 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 of town B.

Here is the algorithm for the validation loops:

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++

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr