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]
4 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]4 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
Allow the user to enter a series of temperatures in degrees Celsius (C) ter-
adoni [48]
The flow chart would go:

----------------------------
Start

Input C (Celsius)

IF C = -999 THEN END

Calculate F (Fahrenheit) using the formula

Output F

Goto next temperature (Input C)
----------------------------

The above needs tidying up and coding in the computer language you are using.
5 0
4 years ago
40 POINTS PLZ HELP NEED ASAP!!!
dem82 [27]
I Think The answer is c I hope it helps Message Me if I’m wrong and I’ll change My answer and fix it for you
7 0
3 years ago
.
yan [13]

The correct answer is a paper bag

7 0
4 years ago
What is the error in this program?
WINSTONCH [101]

The error in this program above is that All the blocks should be in one connected stack to function.

<h3>What are the errors in a program?</h3>

In the act of developing a programs there are some kinds of error that can take place such as syntax errors, logic errors and others.

Note that in the program above, The error in this program above is that All the blocks should be in one connected stack to function and thus there is an error.

Learn more about program from

brainly.com/question/1538272

#SPJ1

5 0
2 years ago
Which of these statements best compares P waves and S waves of an earthquake?
vlabodo [156]
Fam Try C.<span>S waves do not travel through molten rocks but P waves travel through molten rocks.</span>
3 0
3 years ago
Other questions:
  • Walt needs to ensure that messages from a colleague in another organization are never incorrectly identified as spam. What shoul
    14·2 answers
  • Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than
    6·1 answer
  • How can employees advance their current skills or expertise in a particular occupation?
    13·1 answer
  • How would a static local variable be useful?
    5·1 answer
  • Drugs of addiction act upon a portion of the Brain called the lambic system ? True or false.
    7·1 answer
  • Which formal security-related process should take place at the beginning of the code creation project? Group of answer choices R
    13·1 answer
  • Today when Dylan turned on his computer, he noticed that the monitor was very dim. He could still see the desktop icon and text.
    15·1 answer
  • which driver must be running and configured to enable a PC to communicate with a CompactLogix PLC on an Ethernet network
    10·1 answer
  • A python program for the following output using for loop.
    13·1 answer
  • Question 1 of 10
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!