Hi,

I'm a student new to C++, just started learning it for 3 weeks. I just encountered a problem in making a multiplication table as an assignment.
Tried alot of methods but still can't figure out what's wrong.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int input, num1, num2;

    cout << "This is a multiplication table program.\n" <<
            "Please enter a number and the result will be shown.\n\n";
    cin >> input;
    cout << "\n\n";
    
    for ( int num3 = 0; num3 <= input; num3++ )
    cout << setw (6) << right << num3;
    cout << "\n\n" ;
    
    
    for ( num1 = 1; num1 <= input; num1++ )
    {
        cout << setw (6) << right << num1;
        
        for ( num2 = 1; num2 <= input; num2++ )
        cout << setw (6) << right << 
        num2 * num1 << " ";
        cout << "\n\n" ;
    
    }     
 
    system("pause");  
    return 0;
}

What happens is that the first line shown is totally out of place.
Thanks for looking.
P.S. I had alot of help from this website by reading up. Thanks!

Chane this line:

num2 * num1 << " ";

to this:

num2 * num1;

and the numbers will line up.

Wow, thanks for the quick reply.
I didn't notice that " " because I put it in very early.
Aaaaa now I feel stupid =\

Thanks anyway =]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.