# Help with a program (beginner)

• March 6th, 2013, 12:41 PM
gluecows
Help with a program (beginner)
I have a question for one of my high school programming projects and i'm not really sure where to start. Here's the problem.

"Mexico's population is 62 million and is growing at the annual rate of 7%. The United States' current population is 280 million and is growing at the annual rate of 2%. If these two countries were to maintain their current rates of growth, in how many years will Mexico's population be more than half that of the United States? Your program should answer this question."

I decided to make it so it would run Mexico's population * 1.07^years and USA's pop * 1.02^years

but when I run my program it says that Mexico's pop. catches up to half of the USA's in 1 year which is definitely not true. (the answer is 18 years)

Any help is appreciated! :)

Code java:

```import java.util.Scanner; public class h3q3 { public static void main (String [] args){ Scanner scan = new Scanner (System.in);   double mex = 62000000; double usa = 280000000; double years = 0;   while(mex <= usa/2) { years++; mex = mex * Math.pow(1.07, years); usa = usa * Math.pow(1.02, years); if (mex > (usa/2));{ break; } } System.out.println ("Mexicos population is half of America's in " + years + "years "); } }```
• March 6th, 2013, 01:13 PM
Norm
Re: Help with a program (beginner)
Try computing the values manually for each year for a couple of years and writing the values on a piece of paper. One line for each year.
Add a println statement to the code to print out the same values that were manually computed for each year.
Compare the values.
Change the program so it computes the same values for a year as were manually computed.
• March 6th, 2013, 01:37 PM
gluecows
Re: Help with a program (beginner)
I did what you said. It took some time but I figured out my issue and got the program to work. Thanks!
• March 6th, 2013, 01:41 PM
Norm
Re: Help with a program (beginner)
You're welcome.