// This is for funsies - more fun with arrays // Let's play with an array of structs // I have a huge collection of board games. I would like to // find most popular game in my collection #include enum game_type { COOPERATIVE, STRATEGY, AREACONTROL, CARD, DUNGEONCRAWLER, ABSTRACT }; struct board_game { enum game_type type; int popularity_score; int accessibility_rating; char name_initial; }; int main(void) { struct board_game game_list[3]; for (int i = 0; i < 3; i++) { game_list[i].type = STRATEGY; game_list[i].popularity_score = i; game_list[i].accessibility_rating = i + 1; game_list[i].name_initial = 'C'; } game_list[2].type = DUNGEONCRAWLER; game_list[2].popularity_score = 8; game_list[2].accessibility_rating = 5; game_list[2].name_initial = 'S'; for (int i = 0; i < 3; i++) { printf("Game %d\n" "Type: %d\n" "Popularity: %d\n" "Accessibility: %d\n" "Initial: %c\n", i, game_list[i].type, game_list[i].popularity_score, game_list[i].accessibility_rating, game_list[i].name_initial); } int index = 0; int most_popular = 0; for (int i = 0; i < 3; i++) { if (game_list[i].popularity_score > most_popular) { most_popular = game_list[i].popularity_score; index = i; } } printf("MOST POPULAR Game %d\n" "Type: %d\n" "Popularity: %d\n" "Accessibility: %d\n" "Initial: %c\n", index, game_list[index].type, game_list[index].popularity_score, game_list[index].accessibility_rating, game_list[index].name_initial); return 0; }