/* Olympics.c (c) Kari Laitinen http://www.naturalprogramming.com 1997-??-?? File created. 2013-11-27 Last modification. */ #include #include #include struct Olympics { int olympic_year ; char olympic_city[ 20 ] ; char olympic_country[ 20 ] ; } ; struct Olympics olympics_table[] = { 1896, "Athens", "Greece", 1900, "Paris", "France", 1904, "St. Louis", "United States", 1906, "Athens", "Greece", 1908, "London", "Great Britain", 1912, "Stockholm", "Sweden", 1920, "Antwerp", "Belgium", 1924, "Paris", "France", 1928, "Amsterdam", "The Netherlands", 1932, "Los Angeles", "United States", 1936, "Berlin", "Germany", 1948, "London", "Great Britain", 1952, "Helsinki", "Finland", 1956, "Melbourne", "Australia", 1960, "Rome", "Italy", 1964, "Tokyo", "Japan", 1968, "Mexico City", "Mexico", 1972, "Munich", "West Germany", 1976, "Montreal", "Canada", 1980, "Moscow", "Soviet Union", 1984, "Los Angeles", "United States", 1988, "Seoul", "South Korea", 1992, "Barcelona", "Spain", 1996, "Atlanta", "United States", 2000, "Sydney", "Australia", 2004, "Athens", "Greece", 9999, "end of table", "end of table" } ; int main() { int given_year ; int olympics_index = 0 ; printf( "\n This program can tell you where the modern Olympic " ) ; printf( "\n Games were held in a given year. Please, give a year "); printf( "\n by using four digits: " ) ; scanf( "%d", &given_year ) ; bool table_search_ready = false ; while ( table_search_ready == false ) { if ( olympics_table[ olympics_index ].olympic_year == given_year ) { printf( "\n\n In %d, Olympic Games were held in %s, %s.\n", given_year, olympics_table[ olympics_index ].olympic_city, olympics_table[ olympics_index ].olympic_country ) ; table_search_ready = true ; } else if ( olympics_table[ olympics_index ].olympic_year == 9999 ) { printf( "\n\n Sorry, no Olympic Games were held in %d.\n", given_year ) ; table_search_ready = true ; } else { olympics_index ++ ; } } } /* The return type of a C main() method should be int. The following was found at stackoverflow: I continue to write return 0; at the end of a main() function, even though C99 permits you to omit any return there (and it then behaves as if you wrote return 0;). */