Headers for 2D multiplication table array

This is a discussion on Headers for 2D multiplication table array within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I've been trying to make a 2D multiplication table array. So far I've got everything down but I ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    4

    Headers for 2D multiplication table array

    Hi guys, I've been trying to make a 2D multiplication table array. So far I've got everything down but I need the headers so my times table looks something like this:

    1 2 3 4 5 6 < Headers
    1 1 2 3 4 5
    2 2 4 6 8 10

    ^Headers.

    Can someone help me out?

    Code:
    #include <iostream>
    Code:
    #include <iomanip>
    
    
    using namespace std;
    
    
    int main ()
    
    
    {
        for (;;) 
        {
            int rows, columns;
            system("title Assignment 1 Multiplication table edoc s'nevets");
            system("cls");
            cout<<"Please enter the number of rows\n"<<endl;
            cin>>rows;
            cout<<"\nPlease enter the number of columns\n"<<endl;
            cin>>columns;
            system("cls");
            
            cout<<endl;
    
    
            for (int y = 1; y <= rows; y++)
            { 
                cout<<setw(5);
                for (int x = 1; x <= columns; x++)
                {
                    cout<<x*y<<setw(5);
                }
                cout<<endl<<endl;
            }
            cin.get();cin.get();cin.get();
        }
        return 0;
    }

    Last edited by Capt'n America; 02-02-2013 at 09:16 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Really?

    So given an input like columns, you can't write
    for ( i = 1 ; i <= columns ; i++ ) cout << i << " ";

    The row headings are even simpler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    Quote Originally Posted by Salem View Post
    Really?

    So given an input like columns, you can't write
    for ( i = 1 ; i <= columns ; i++ ) cout << i << " ";

    The row headings are even simpler.
    Oh yeah thanks, other than acting like a grandeur of c++, you definitely showed me how to input headers into my table without messing up the array...

    You know, if I knew everything why the hell would I be asking for help?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Presumably, you noticed that the header row is in fact the same as the first row of the results (aka multiplied by 1).
    This should have been a clue.

    Well you seemed to master the hard part of the problem without any issue, yet came over all "stupid" for the easy part.

    Which round these parts usually means someone "found" some code on the net somewhere, then they roll into a forum claiming this, that or the other trying to get us to finish off their assignment without them having to bother with the tedium of learning things or doing the work themselves.

    Sorry if I didn't put enough sugar on the reply.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    Quote Originally Posted by Salem View Post
    Presumably, you noticed that the header row is in fact the same as the first row of the results (aka multiplied by 1).
    This should have been a clue.

    Well you seemed to master the hard part of the problem without any issue, yet came over all "stupid" for the easy part.

    Which round these parts usually means someone "found" some code on the net somewhere, then they roll into a forum claiming this, that or the other trying to get us to finish off their assignment without them having to bother with the tedium of learning things or doing the work themselves.

    Sorry if I didn't put enough sugar on the reply.
    How To Ask Questions The Smart Way
    I think in reality, sometimes what comes over as hard comes over as easy for one man, and for another man what comes over easy comes over hard for another.

    I'm not sure what you're trying to come off of but telling me to ask questions "the smarter way" for a solution that is so "easy",which I believe, only insults your intelligence.
    I may not be acquainted with programming too well... But I'm well aware of the overall atmosphere on any "typical" forum, oh yeah usually it's simple and easy with a hint of assumptions and generalizations here and there, I guess that's why some forums have flame forums. But at least in America as far as I'm aware we like simplification.

    And with that, there's no need to make a simplified statement to an already "easy" question in your excellence.

    I don't intend or expect anyone to do my "dirty work" for me. Nor do I want you to do my work. I came here to seek guidance from a community of which I thought would be a bunch of helpful and humble folks, and so far my experience hasn't been beneficial. Talk about eye opening then we'll just have to go down another route for "eye opening."

    Now with a proper opening... Sure I am a newcomer that so happened to "luck out" on the hard part, yeah I get how it works here and there. But with the headers I don't see what you're saying with your initial response. As soon as I make an alignment in one row my whole table is messed up. cout << i << " "; does not help the situation.

    Of course it prints the header but then my multiplication table is no longer what it is.

    I can use cout<< to declare the header on top of the rows and the columns but I can't get it to change variably to the user's input

    user inputs numbers 5 x 5


    * 1 2 3 4 5
    1 Array
    2 Table
    3
    4
    5

    I've tried all that "\t" stuff and as I said before my table just becomes miss-aligned.
    Last edited by Capt'n America; 02-03-2013 at 09:02 AM.

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    Well nvm I figured it out after hours of perseverance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiplication table
    By yatesj05 in forum C Programming
    Replies: 7
    Last Post: 04-17-2011, 02:46 AM
  2. C Multiplication Table
    By trueman1991 in forum C Programming
    Replies: 2
    Last Post: 11-11-2009, 06:58 AM
  3. Multiplication Table using Array.
    By iLike in forum C Programming
    Replies: 1
    Last Post: 11-01-2009, 04:56 PM
  4. Multiplication table
    By freddyvorhees in forum C++ Programming
    Replies: 6
    Last Post: 08-02-2008, 11:09 AM
  5. multiplication table help
    By cprogstudent in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21