Declare a structure which describes an individual video game. Video games have a title, genre, platform, developer, year of release, lower age limit, a price and whether or not they support in-app purchases. You will need to pick appropriate data types of each piece of information to be stored in the structure.
- Name the structure: Video_Game.
- Declare three video game structure variables locally in the main function, called game1, game2 and game3.
- Assign to the members of game1, the details for the Candy Crush Saga (King, 2012) example above.
- Assign to the members of game2, the details for the Halo 4 (343 Industries, 2014) example above.
- Assign to the members of game3, the details for your favourite game… if you don’t play games, check your smart phone… surely you play something on there… if not, check the relevant app store top charts and find a game that could become your new favourite!
- Next, declare a function called print_video_game_details() which takes in a parameter that is a pointer to video game structure declared earlier. In this function, print out the details of the game passed to the function, in the style shown above for the Candy Crush Saga and Halo 4 examples.
- Next, call the print_video_game_details function three times from main, passing in the address of game1, game2 and game3, after the members have all been set.
My code so far:
#include <stdio.h>
#include <string.h>
struct video_game
{
char* title;
char* genre;
char* developer;
int year;
char* platform;
int lower_age;
float price;
char* inapp_purchase;
}game1, game2;
void print_video_game_details()
{
for(int i =1; i<=3; i++)
{
printf("Title: %s", game[i].title); // game[i] is showing an error "undeclared"
printf("Genre: %s", game[i].genre);
printf("Developer: %s", game[i].developer);
printf("year of release: %d", game[i].year);
printf("platform: %s", game[i].platform);
printf("lower age: %d", game[i].lower age);
printf("price: %f", game[i].price); //is showing an error "incompatible"
printf("inapp_purchase: %s", game[i].inapp_purchase);
}
}
int main(void)
{
game1.title = "Candy crush saga";
game1.genre = "Match-Three Puzzle";
game1.developer = "King";
game1.year = "2012";
game1.platform = "Android, ios, Windows Phone";
game1.lower_age = "7";
game1.price = "$0.00";
game1.inapp_purchase = "yes";
print_video_game_details();
}
I am not able to print out the structure as it won't compile.
ERRORS:
prog.c: In function 'print_video_game_details':
prog.c:27:33: error: 'struct video_game' has no member named 'lower'
printf("lower age: %d", game[i].lower age);
^
prog.c:27:40: error: expected ')' before 'age'
printf("lower age: %d", game[i].lower age);
^
prog.c: In function 'main':
prog.c:39:15: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
game[0].year = "2012";
^
prog.c:41:20: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
game[0].lower_age = "7";
^
prog.c:42:16: error: incompatible types when assigning to type 'float' from type 'char *'
game[0].price = "$0.00";
^