Here's the C++ Programming Exercise: The population of town A is less than the population of town B. However, the population of town A is growing faster than the population of town B.Write a program that prompts the user to enter: 1. The population of town A 2. The population of town B 3. The growth rate of town A4. The growth rate of town B The program outputs: 1. After how many years the population of town A will be greater than or equal to the population of town B 2. The populations of both the towns at that time.(A sample input is: Population of town A = 5,000, growth rate of town A = 4%, population of town B = 8,000, and growth rate of town B = 2%.) Now here's my solution: #include <iostream>using namespace std;int main(){//declare variablesint pop_A;int pop_B;int year = 1;double growth_rate_A;double growth_rate_B;//Prompt the user to input the population and growth rate of Town A.cout <<"Enter the population and growth rate of Town A: ";cin >> pop_A >> growth_rate_A;cout << endl;//Prompt the user to input the population and growth rate of Town B.cout <<"Enter the population and growth rate of Town B: ";cin >> pop_B >> growth_rate_B;cout << endl;if (pop_A < pop_B && growth_rate_A > growth_rate_B){do {(pop_A = ((growth_rate_A /100) * pop_A) + pop_A); //calculates the population growth in one year.(pop_B = ((growth_rate_B / 100) * pop_B) + pop_B); year++;} while (pop_A < pop_B);int pop_Diff = pop_A - pop_B;int pop_Total = pop_A + pop_B;cout <<"Town A will surpass Town B in population after " << year << " years." << endl;cout << "The final population of Town A is: " << pop_A << endl;cout << "The final population of Town B is: " << pop_B << endl;cout << "In year " << year << ", Town A has " << pop_Diff << " more people than Town B." << endl;cout << "The total population of both Town A and Town B is " << pop_Total << endl;} else{cout << "The Values Doesn't Compute.";}return 0;} My class is conducted in Cengage. As a result, the test case's numbers are rather odd, and it's causing Cengage to reject my lab. The numbers used for test case #1 are: 44, 240, 44 and 30. The numbers for test case #2 are: 50000, 75000, 25 and 12. Both outputs are "The Values Doesn't Compute." Can someone help me to find out how to accomidate these crazy Cengage test values?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 20PE: When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making...
icon
Related questions
icon
Concept explainers
Question

Here's the C++ Programming Exercise:

The population of town A
is less than the population of town B.
However, the population of town A
is growing faster than the
population of town B.

Write a program that prompts the
user to enter:

1. The population of town A
2. The population of town B
3. The growth rate of town A
4. The growth rate of town B

The program outputs:

1. After how many years the
population of town A will be
greater than or equal to the
population of town B

2. The populations of both the
towns at that time.

(A sample input is: Population of
town A = 5,000, growth rate of town
A = 4%, population of town B =
8,000, and growth rate of town B =
2%.)

Now here's my solution:

#include <iostream>
using namespace std;
int main()
{
//declare variables
int pop_A;
int pop_B;
int year = 1;
double growth_rate_A;
double growth_rate_B;
//Prompt the user to input the population and growth rate of Town A.
cout <<"Enter the population and growth rate of Town A: ";
cin >> pop_A >> growth_rate_A;
cout << endl;
//Prompt the user to input the population and growth rate of Town B.
cout <<"Enter the population and growth rate of Town B: ";
cin >> pop_B >> growth_rate_B;
cout << endl;
if (pop_A < pop_B && growth_rate_A > growth_rate_B)
{
do {
(pop_A = ((growth_rate_A /100) * pop_A) + pop_A); //calculates the population growth in one year.
(pop_B = ((growth_rate_B / 100) * pop_B) + pop_B); year++;
} while (pop_A < pop_B);
int pop_Diff = pop_A - pop_B;
int pop_Total = pop_A + pop_B;
cout <<"Town A will surpass Town B in population after " << year << " years." << endl;
cout << "The final population of Town A is: " << pop_A << endl;
cout << "The final population of Town B is: " << pop_B << endl;
cout << "In year " << year << ", Town A has " << pop_Diff << " more people than Town B." << endl;
cout << "The total population of both Town A and Town B is " << pop_Total << endl;
} else
{
cout << "The Values Doesn't Compute.";
}
return 0;
}

My class is conducted in Cengage. As a result, the test case's numbers are rather odd, and it's causing Cengage to reject my lab. The numbers used for test case #1 are: 44, 240, 44 and 30. The numbers for test case #2 are: 50000, 75000, 25 and 12. Both outputs are "The Values Doesn't Compute." Can someone help me to find out how to accomidate these crazy Cengage test values?

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

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