Thread: Help with SPACING

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    12

    Help with SPACING

    This is my multiplication table program;

    #include <iostream.h>
    int main()
    {
    for (int x = 0; x < 10; x++) {
    for (int y = 0; y < 10; y++) {
    cout << x*y << " ";
    }
    cout << endl;}
    return 0;
    }

    my output is:

    0 0 0 0 0 0 0 0 0
    0 1 2 3 4 5 6 7 8 9
    0 2 4 6 8 10 12 14 16 18
    0 3 6 9 12 15 18 21 24 27
    0 4 8 12 16 20 24 28 32 36
    0 5 10 15 20 25 30 35 40 45
    0 6 12 18 24 30 36 42 48 54 etc.......

    Just want to now wat I have to do so that my table is spaced out evenly like this:


    0 0 0 0 0 0 0 0 0 0
    0 1 2 3 4 5 6 7 8 9
    0 2 4 6 8 10 12 14 16 18
    0 3 6 9 12 15 18 21 24 27
    0 4 8 12 16 20 24 28 32 36
    0 5 10 15 20 25 30 35 40 45
    0 6 12 18 24 30 36 42 48 54

    Any help would be greatly appreciated. THX

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main() 
    {
        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
                cout << setw(3) << x*y;
            cout << endl;
        }
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    hmmmm there was a mistake in the second output that i types. the spacing should make it a table that looks like a "box-shaped" multiplication table. anyways ill try your suggestion hkmp5

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    this works out perfectly hkmp5 (u play CS?) but i was just wonderin if u can make the spacings right without the use of ....
    #include <iomanip>
    using namespace std;
    THX

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <iostream.h>
    int main() 
    {
        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
            {
                cout.width(3);
                cout << x*y;
            }
            cout << endl;
        }
        return 0;
    }
    No I don't play CS, I just love HK's product.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    THX so much for all the help!

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Meaning ...

    I did understand the program ...
    but I couldn't understand your word

    can you tell me please what is the meaning of don't play CS...
    Thanx
    C++
    The best

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    You can code it like this....

    #include <iostream.h>
    int main()
    {
    for (int x = 0; x < 10; x++)
    {
    for (int y = 0; y < 10; y++)
    {
    cout.width(3);
    cout << x*y;
    }
    cout << endl;
    }
    return 0;
    }
    C++
    The best

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >can you tell me please what is the meaning of don't play CS...
    CS is a game called Counter Strike, it has nothing to do with C++. Unless it was programmed with C++, I'm not sure.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    You can code it like this....

    #include <iostream.h>
    int main()
    {
    for (int x = 0; x < 10; x++)
    {
    for (int y = 0; y < 10; y++)
    {
    cout.width(3);
    cout << " | " <<x*y;
    }
    cout << endl;
    cout<< endl;
    }
    cout<< "that will make some spaces ....";
    cout<< " that is the Mult table.... I can print it to my lettle Broo";
    cout<< " ";
    return 0;
    }
    C++
    The best

  11. #11
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    There is one in the universe....

    Prelude...
    You are the one in the universe... thax alot for helping us....

    Thankx
    C++
    The best

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    12
    THX for all the help guys i really appreciate it. When I said CS i meant the game counter-strike

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Better spacing issues
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2008, 04:46 PM
  2. lowest spacing between numbers
    By Ene Dene in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2007, 04:08 PM
  3. Dev C++ Spacing Problem
    By Darklighter137 in forum C++ Programming
    Replies: 7
    Last Post: 11-13-2006, 10:48 AM
  4. Spacing between printf statements
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 08-03-2006, 10:02 AM
  5. Spacing?
    By trenzterra in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:42 PM