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
Corey wrote a code that will display his name every time he presses the down arrow key but there is a bug in it. Display letter
brilliants [131]

Answer:

Explanation:

display letter c, type letter r, type letter o, type letter 3, type letter y- i think thats it but i dee cay this is confusing

7 0
2 years ago
Timothy was reading tournament results of the football World Cup matches on Infogoalistic.com. As he was going through the resul
Gennadij [26K]

Answer:

B) contextual

Explanation:

Contextual advertising is a form of targeted advertising for advertisements appearing on websites or other media.

For example:

Timothy was reading tournament results of the football World Cup matches on Infogoalistic.com. As he was going through the results, an advertisement of new football studs popped up. This is an example of <u>contextual</u> advertising.

5 0
2 years ago
Does anyone play fortnite i want to be gifted vbucks please my epic is Springtrap_locks thx means a lot to me
Paladinen [302]

Answer:

This is not what this platform is supposed to be used for

Explanation:

Fortnite isnt a real game lol get a life

3 0
3 years ago
Someone who wants the credential of skilled training but in less time than a four-year degree should consider
Katyanochek1 [597]
They should consider an associates degree or certifications. =)
8 0
3 years ago
When you tap or click the ____ button for a selected graphic, Word provides options for changing how a graphic is positioned wit
Snowcat [4.5K]
<span>You have to click on "layout options" to enable you to change the positioning of a graphic within a Word document. You will be able to change how the graphic wraps around text, is scaled to the page/document and if it should have borders etc around it.Hope this helps. Let me know if you need additional help!</span>
5 0
3 years ago
Other questions:
  • Peripherals can be used to input information. True False
    6·2 answers
  • A firewall, when properly implemented, can prevent most attacks on your system.
    11·1 answer
  • How to cite a website, like asha.org?
    6·1 answer
  • The _____ dialog box lets you specify which files are to be merged.
    14·1 answer
  • A manager would like information on the knowledge base searches conducted by customers and call center agents. Which two metrics
    10·1 answer
  • Write a filter that reads in a sequence of integers and prints the integers, removing repeated values that appear consecutively.
    5·2 answers
  • The processing power of a computing device is measured by its _____.
    10·1 answer
  • Anyone know what this is pls help
    11·1 answer
  • What kind of goal does ariel set when he works to graduate from high school in four years? short term long term normative fantas
    9·1 answer
  • Resource _____ let you view, manage, and automate tasks on multiple aws resources at a time.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!