Need help with loop!

Hi,

I need help writing this loop, I have an idea of how to write it but I'm not sure if it's correct. Here's the question:


# of
Country Athletes Gold Silver Bronze

Canada 212 83 75 44
China 323 34 16 73
England 120 14 53 9
France 88 12 18 58
Germany 202 47 39 71
Italy 67 29 8 19
Mexico 45 10 3 24
Nigeria 56 4 11 18
Poland 76 7 6 22
U S 443 73 10 17


Use the following format for the data:

country name: character
number of athletes: integer
number of gold medals won: integer
number of silver medals won: integer
number of bronze medals won: integer




(b) Write loop that will output each country name and total number of medals won.
Last edited on
All you need is a loop:
for (int i = 0; i < numberOfAthletes; ++i) printf("<whatever data you want here>");
That's all I need to output the number of countries and their total number of medals one, respectfully?
You put numberOfAthletes - I don't need the number of athletes, all I need is a loop to output Country Name & Total Number of Medals Won for EACH country.

Thanks in advance
Yes, but you need to know how many there are, if you want to print them all. The number isn't printed; it's just used as the loop bound. It means it will execute the statement "numberOfAthletes" times.
Topic archived. No new replies allowed.