I need some help to make this program work.

Discussion in 'C++' started by lov3np3ac3, Jun 9, 2012.

  1. lov3np3ac3

    lov3np3ac3 New Member

    Jun 9, 2012
    Likes Received:
    Trophy Points:
    So I kind of started the program but I can't manage to make it work properly. Can anyone please help me make it work?
    //Create a program which lets the user choose a game genre,
    //afterwards a game from the sub-menu for the selected genre
    //and show some information about the selected game, previously
    //entered in the program.
    //Afterwards, the user rates the game on the scale from 1 to 10.
    //After 10 users have selected and rated the games, the program
    //shows the rating of the games.
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    #define N_GAMES 4 // number of games
    struct games_t {
        int id;
        string genre;
        string name;
        string info;
        int rating;
    } games [N_GAMES];
    string genres[] = {"RPG","Action games","Racing games","FPS games"};
    void inputgames (int gcount);
    void printgame (games_t game);
    int main()
        int gcount = sizeof( genres ) / sizeof( genres[ 0 ] ); // getting the size of genres table
        string mystr;
        // function to input gamedata
        // listing inputted games
        cout << "\nYou have entered these games:\n";
        for (int i=0; i<N_GAMES; i++) {
            printgame (games[i]);
        cout << "\n\n";
        cout<<"What kind of games are you interested in?"<<endl;
        for (int i=0;i<gcount;i++)
        int myChoice;
        cout<<"(Please enter a number): ";
        cin>>myChoice; //get the choice
        cout<<"You have selected the following genre: "+  genres[myChoice-1] <<endl;
        cout<<"listing games by genre: \t\t"<<endl;
        for (int i = 0; i< N_GAMES; i++) 
            if (games[i].genre.compare(genres[myChoice-1]) == 0) {
                cout << games[i].id << ": " << games[i].name << endl;
        cout<<"Please select a interesting game:"<<endl;
        int gamechoise;
        cout<<"you have selected the following game: " + games[gamechoise].name <<endl;
        cout<<"here is some useless info about that game:"<<endl;
        cout<<"rate the game pl0x (1-10)"<<endl;
        getline (cin,mystr);
        stringstream(mystr) >> games[gamechoise].rating;
        system ("pause");
        return 0;
    void inputgames (int gcount) {
        int n;
        cout << "Insert the game data."<<endl;
        for (n=0; n<N_GAMES; n++)
            games[n].id = n;
            cout << "Select genre from following: "<<endl;
            for (int i = 0; i < gcount; i++) { // listing genres
                cout << i+1 << "\t\t" << genres[i] << endl;
            cout<<"(Please enter a number between 1 - " << gcount << "): ";
            int myChoice;
            games[n].genre = genres[myChoice-1];
            cout << "Enter name: ";
            getline (cin,games[n].name);
            cout << "Enter info: ";
            getline (cin, games[n].info);
            cout << "\n";
    void printgame (games_t game)
        cout << game.genre;
        cout << " <> " + game.name;
        cout << " <> " + game.info + "\n";
    So as the comment at the start says, the program needs to let the user pick a game genre,a game from the sub-menu of said game genre and then show some info about the game which is previously entered into the program. Afterwards, the user should be able to rate the game and after 10 users have selected and rated games, the program should show the rating of the games.

    I would very much appreciate it if anyone helps me make this work. The code is still messy and I'm a beginner but I was given the task of making this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice