Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:11:24+00:00 2026-06-05T20:11:24+00:00

I want to just hard code these values into a table. when I try

  • 0

I want to just hard code these values into a table. when I try to use 2D arrays, I run into the problem of dealing with characters and integers. 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)

#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[i].game;
         std::cout << "\tYear: " << setw(4) << tabl[i].year;
         std::cout << "\tRating: " << fixed << setprecision(2) << tabl[i].rating;
         std::cout << "\tVoters: " << setw(6) << tabl[i].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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:11:27+00:00Added an answer on June 5, 2026 at 8:11 pm

    What I think you are looking for is <iomanip>

    #include <iomanip>
    
    std::cout << "Game: " << setw(20) << tabl[i].game;
    std::cout << "\tYear: " << setw(4) << tabl[i].year;
    std::cout << "\tRating: " << fixed << setprecision(3) << tabl[i].rating;
    std::cout << "\tVoters: " << setw(6) << tabl[i].num_voters;
    std::cout << std::end;
    

    Notes:
    setw adds padding when writing out stuff, so it will always be at least a certain width
    setprecision specifies how many decimal places to display
    fixed makes floating point never use scientific notation

    Your game member is a letter, and you’re attemptying to assign it a string. Don’t use strcpy in C++, use the std::string class instead.

    #include <string>
    struct table
    {
        std::string game;
        int year;
        double rating;
        int num_voters;
    };
    

    Avoid using namespace std;, when you get to complex code with many namespaces, those few letters are a small price to pay for avoiding confusion.
    Avoid endl: it flushes buffers which is slow. If you just want a newline, use '\n'.
    Also, you can use the new initialization syntax to initialize your list:

    std::vector<table> tbal = { 
                     {"twilight struggles  ", 2005, 8.226, 10690},
                     {"Agricola            ", 2007, 8.17 , 23738},
                     {"Puerto Rico         ", 2002, 8.163, 27433}
                   };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an app to block GtalkService. I want just use iptables for
I just want to ask if is it okay that I use native PHP
i just want to know, how to write Code behind(Hyperlink1_Click()), for the hyper link
I want a hard reference class in my Java code, but, of course, there
I realize that without code this might be hard to answer but the problem
I want just get Image( .JPG , .PNG , .Gif ) File from my
With php file_get_contents() i want just only the post and image. But it's get
I just want to ask if anybody has done something like this. Basically, it's
I just want to add some extra text on top of input posted from
I just want to know why both the paint and draw methods are used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.