C++ question I cant understand
Results 1 to 4 of 4

Thread: C++ question I cant understand

  1. #1
    IT Specialist Ghost_25inf's Avatar
    Join Date
    Sep 2001
    Location
    Michigan
    Posts
    648

    C++ question I cant understand

    0 0 0 0 0 0 0 0 0 0 0
    0 1 2 3 4 5 6 7 8 9 10
    0 2 4 6 8 10 12 14 16 18 20
    0 3 6 9 12 15 18 21 24 27 30
    0 4 8 12 16 20 24 28 32 36 40
    0 5 10 15 20 25 30 35 40 45 50
    0 6 12 18 24 30 36 42 48 54 60
    0 7 14 21 28 35 42 49 56 63 70
    0 8 16 24 32 40 48 56 64 72 80
    0 9 18 27 36 45 54 63 72 81 90
    0 10 20 30 40 50 60 70 80 90 100

    this is the end result im tring to come up with can anyone help.


    # include <iostream>
    using namespace std;
    int main ()
    {
    int across;
    int down;
    for ( across =0 ; across <=10 ; across ++)
    for ( down =0 ; down <=10 ; down ++)
    cout << across * down;
    return 0;
    }

    this is where i ended up. missing something to allow it to display properly. this program is a multiplication table where I can enter a number and it will display the approperate diagram.
    S25vd2xlZGdlIGlzIHBvd2VyIQ

  2. #2
    Senior Member
    Join Date
    Nov 2002
    Posts
    393
    using namespace std;
    what does that mean ? i havent learned about that.
    \"I have a 386 Pentium.\"

  3. #3
    Junior Member
    Join Date
    Aug 2002
    Posts
    27
    The problem is you have no spaces or newline characters in your program. Also, you have it set to print out columns, while it would be much easier to just make it print rows first, then use an endl.

    Here's my (untested) edit:

    Code:
    # include <iostream> 
    using namespace std; 
    int main () 
    { 
       int across; 
       int down; 
       for (down =0 ; down <=10 ; down++) 
       {
            for (across =0 ; across <=10 ; across++) 
                 cout << across * down << " ";
            cout << endl;
       }
       return 0; 
    }
    edit: formatting issues
    My $0.02

  4. #4
    () \/V |\| 3 |) |3\/ |\|3G47|\/3
    Join Date
    Sep 2002
    Posts
    744
    This block of code will get the desired results.

    ---------------------------------------------------------------------------------
    #include <iostream.h>

    int main()
    {
    int across;
    int down;
    for (across =0 ; across <=10 ; across ++)
    {
    for (down =0 ; down <=10 ; down ++)
    cout << across * down << " ";
    cout << endl;
    }
    return 0;
    }
    ---------------------------------------------------------------------------------

    Output


    0 0 0 0 0 0 0 0 0 0 0
    0 1 2 3 4 5 6 7 8 9 10
    0 2 4 6 8 10 12 14 16 18 20
    0 3 6 9 12 15 18 21 24 27 30
    0 4 8 12 16 20 24 28 32 36 40
    0 5 10 15 20 25 30 35 40 45 50
    0 6 12 18 24 30 36 42 48 54 60
    0 7 14 21 28 35 42 49 56 63 70
    0 8 16 24 32 40 48 56 64 72 80
    0 9 18 27 36 45 54 63 72 81 90
    0 10 20 30 40 50 60 70 80 90 100
    Press any key to continue

    Go Finland!
    Deviant Gallery

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •