Array of struct

Discussion in 'Software' started by r0vanz01, Jun 18, 2012.

  1. r0vanz01

    r0vanz01

    Joined:
    Jun 18, 2012
    Messages:
    1
    I want to just hard code these values into a table. When I do a struct I have this so far but it doesn't divide the information up in columns, and I'm not sure how to format it that way. (I only did 3 rows to start off with, if I get them working, the rest will just be the same).
    It says the application has requested the Runtime to teniminate it in an unusual way. And then it crashes


    #include <iostream>
    #include <string>
    #include <iomanip>

    using namespace std;

    typedef struct table
    {
    std::string game;
    int year;
    float rating;
    int num_voters;
    }t;

    void processTab(t*);
    int main()
    {
    t tabl[2] = {0,0};
    int i;
    processTab(tabl);
    for(i=0; i<2; i++)
    {
    std::cout << "Game: " << setw(20) << tabl.game;
    std::cout << "\tYear: " << setw(4) << tabl.year;
    std::cout << "\tRating: " << fixed << setprecision(2) << tabl.rating;
    std::cout << "\tVoters: " << setw(6) << tabl.num_voters;
    }

    system("pause");
    return 0;
    }
    void processTab(t*tab)
    {
    (tab[0].game, "twilight struggles");
    tab[0].year = 2005;
    tab[0].rating = 8.226;
    tab[0].num_voters = 10690;

    (tab[1].game, "Agricloa");
    tab[1].year = 2007;
    tab[1].rating = 8.17;
    tab[1].num_voters = 23738;

    (tab[2].game, "Puerto Rico");
    tab[2].year = 2002;
    tab[2].rating = 8.163;
    tab[2].num_voters = 27433;

    }

    Table Data:
    Game (0) Year (1) Rating (2) Num Voters (3)
    Twilight Struggle 2005 8.226 10690
    Agricola 2007 8.17 23738
    Puerto Rico 2002 8.163 27433
    Through the Ages 2006 8.153 8137
    Power Grid 2004 8.02 21655
    Le Havre 2008 7.972 9258
    Eclipse 2011 7.968 3194
    Brass 2007 7.911 5814
    Dominion: Intrigue 2009 7.895 10889
    Caylus 2005 7.878 13878
    Last edited: Jun 18, 2012
    r0vanz01, Jun 18, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ultraman Aries

    VC6 Compiler ignores Array indexing?

    Ultraman Aries, Jun 4, 2004, in forum: MCSD
    Replies:
    2
    Views:
    645
    =?Utf-8?B?SSBMb3ZlIEMrKw==?=
    Jun 5, 2004
  2. Alex©

    Cant get rid of RAID array/settings on 2 HDDS

    Alex©, Jul 27, 2003, in forum: Computer Support
    Replies:
    2
    Views:
    2,264
    Thund3rstruck
    Jul 28, 2003
  3. Burtraskkutaren

    _CONTEXT struct in winnt.h with x64?

    Burtraskkutaren, Apr 19, 2006, in forum: Windows 64bit
    Replies:
    6
    Views:
    2,130
    Tony Sperling
    Apr 20, 2006
  4. amrutha0303
    Replies:
    0
    Views:
    961
    amrutha0303
    Aug 3, 2010
  5. amrutha0303
    Replies:
    0
    Views:
    2,100
    amrutha0303
    Aug 3, 2010
Loading...

Share This Page