196k views
5 votes
Assume that the population of Mexico is 114 million and that the population increases 1.01 percent annually. Assume that the population of the United States is 312 million and that the population is reduced 0.15 percent annually. Write an application that displays the populations for the two countries every year until the population of Mexico excceds that of the United States, and display the number of years it took. Save file as Population.java.***NOTE**** This is my first class of java the program that I have to write has to be of what we have learned in the last 6 chapters it cannot have stuff that is way more advanced than the first 6 chapters.

1 Answer

3 votes

Answer:

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

double mexico = 114;

double usa = 312;

double mexicoRate = .0101;

double usaRate = .0015;

// calculate population after every year until mexico population exceed the usa populationn

while (usa>mexico)

{

// print the population

cout<<"Mexico's population ::"<<mexico<<" million."<<endl;

cout<<"USA's population ::"<<usa<<" million."<<endl;

// update the population

mexico+=mexico*mexicoRate;

usa-=usa*usaRate;

}

return 0;

}

Step-by-step explanation:

Declare and initialize mexico and usa with their initial population.Also declare and initial their increase and decrease rate.Find the population of both the country each year until mexico population exceeds the usa population.

Output:

Mexico's population ::114 million.

USA's population ::312 million.

Mexico's population ::115.151 million.

USA's population ::311.532 million.

.

.

.

Mexico's population ::270.546million.

USA's population ::274.213 million.

Mexico's population ::273.278million.

USA's population ::273.802 million.

User Jujka
by
5.7k points