1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mnenie [13.5K]
3 years ago
8

Instructions 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: The population of town A The population of town B The growth rate of town A The growth rate of town B The program outputs: After how many years the population of town A will be greater than or equal to the population of town B The populations of both the towns at that time. (A sample input is: Population of town A
Computers and Technology
1 answer:
weeeeeb [17]3 years ago
6 0

Answer: The c++ program is given below.

#include <iostream>

using namespace std;

int main() {

float townA, townB, growthA, growthB, populationA, populationB;

    int year=0;    

cout<<"Enter present population of town A : ";

cin >> townA;  

cout<<endl<<"Enter present growth rate of town A : ";

cin >> growthA;

growthA = growthA/100;  

cout<<endl<<"Enter present population of town B : ";

cin >> townB;  

cout<<endl<<"Enter present growth rate of town B : ";

cin >> growthB;

growthB = growthB/100;  

do

{

    populationA = townA + (townA * growthA);

    populationB = townB + (townB * growthB);      

    townA = populationA;

    townB = populationB;      

    year++;      

}while(populationA < populationB);  

cout<<endl<<"After " <<year<< " years, population of town A is "<<populationA << " and population of town B is "<< population<<endl;

return 0;

}

Explanation:

All the variables for population and growth rate are declared with float datatype.

The user inputs the present population of both the towns.

The growth rate entered by the user is the percentage growth.

For example, town A has 10% growth rate as shown in the output image.

The program converts 10% into float as 10/100.

growthA = growthA/100;

growthB = growthB/100;

The above conversion is done to ease the calculations.

The year variable is declared as integer and initialized to 0.

The growth in population is computed in a do-while loop. After each growth is calculated, the year variable is incremented by 1.

The loop continues until population of town A becomes greater than or equal to population of town B as mentioned in the question.

Once the loop discontinues, the final populations of town A and town B and the years needed for this growth is displayed.

The new line is introduced using endl keyword.

The function main has return type int hence, 0 is returned at the end of the program.

You might be interested in
Is there similarities between plagiarism and software piracy? explain.​
xz_007 [3.2K]
<h3><u>Plagiarism</u></h3>
  • Plagiarism means using someone else's ideas or words without crediting source.
<h3><u>Pirac</u><u>y</u></h3>
  • Piracy is unauthorized use, reproduction, or sharing of copyrighted material.
3 0
2 years ago
Jesse is writing a physics quiz about the motion of a roller coaster cart. He has a clip art illustration of a cart rolling hori
Aleks04 [339]
<span>editing the image file in a dedicated photo editing program before inserting it</span>
8 0
3 years ago
N one to two sentences, describe what Company ABC should do.
Sunny_sXe [5.5K]

What does Company ABC trying to figure out?

3 0
3 years ago
I have a problem with a task using scipy.optimize.minimize execution through the following methods: CG, BFG, Newton-CG, L-BFGS-B
Scilla [17]

Answer:

Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

3 0
2 years ago
Which of the following types of business ownership has the advantages of pass-through taxation and liability protection?
pshichka [43]
The  type of business ownership that has the advantages of pass-through taxation and liability protection is a corporation. I hope my answer has come to your help. God bless and have a nice day ahead! Feel free to ask more questions.
4 0
3 years ago
Read 2 more answers
Other questions:
  • What are the three fundamental elements of an effective security program for information systems?
    11·2 answers
  • A type of indent where the first line of text starts at the left margin and the second and succeeding lines of text are indented
    7·2 answers
  • Write a grammar for the language consisting of strings built only of the letters a and b. The strings may have any number of the
    6·1 answer
  • Kayla is working on a document for her business meeting. She wants to save this document with another name. Which option should
    5·1 answer
  • Your secondary servers have not been able to contact your primary server to synchronize information. How long will the secondary
    12·1 answer
  • Using pointers and shared memory for IPC, what would you need to add to your code to ensure data integrity?
    15·1 answer
  • QUICK HELP ME PLEASE
    9·1 answer
  • What does angularfirestoremodule. Enablepersistence() do.
    12·1 answer
  • Which type of attack can be addressed using a switched ethernet gateway and software on every host on your network that makes su
    7·1 answer
  • Ginny faced an application error while executing the recorder in opera. Which web browser is generally recommended to use with r
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!