Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C++ table input

  • 06-03-2008 04: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