Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+8 votes

I can find the maximum growth rate, but not the name of the country that goes with it.

asked in old_CSC201 by (1 point)

1 Answer

+2 votes

First, write the code to find the maximum growth rate. That part follows our typical algorithm for finding a max.

Now how about the country name?

After the loop, your code can't go back and find the country name because each time through the loop the country name variable is "overwritten" with the new country name entered by the user. So....that means the country name would need to be saved into a variable (like maxRateCountry) as you pass through the loop. In the body of the conditional statement where you save the growth rate to be the maximum so far, also save the country name in maxRateCountry. Each time the maximum rate is overwritten with the new larger rate, then overwrite the country name saved into maxRateCountry.

answered by (1 point)