Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ table input

  • 06-03-2008 3:38pm
    #1
    Registered Users, Registered Users 2 Posts: 4,502 ✭✭✭


    Hi was on here last week about a small problem, immback again for another little bit of help.

    Im doing a number of successive iterations of a solution through C++ and i want to output the results in a table. I need three columns and the number of rows should will depend on the solution. (ie. there may be more iterations for different solutions so i want the number of rows to be the same as the number of iterations carried out)

    I have tried the help menu but am a bit confused, basic user here.


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    More rows -> Add to an Array?

    Can you be more specific? - bit confusing :)


  • Registered Users, Registered Users 2 Posts: 7,182 ✭✭✭Genghiz Cohen


    A 2 dimensional array?

    An array that has rows and columns.

    int arrayName[numRows][numColumns];

    For your solution you should assign numColumns to 3 and make it a constant.

    const int NUMCOLUMNS = 3;


    Then use nested for loops to iterate through each cell.
    for(int i = 0;i < numRows;i++) //iterate through each row
    {
     for(int j = 0;j<NUMCOLUMNS;j++)// iterate through each column
     {
    cout<<arrayName[i][j]<<"  "; // print the data in the current cell followed by a space
    }
    cout<<endl;// print a new line and move onto the next row
    

    I think that is what you are asking for, I'm not too sure. There is a guide to 2d arrays here


Advertisement