Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,234 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,669 people online right now. Registration is fast and FREE... Join Now!




Multiplication table

 
Reply to this topicStart new topic

Multiplication table, positive and neg numbers

scooby
20 Mar, 2007 - 09:22 AM
Post #1

New D.I.C Head
*

Joined: 23 Feb, 2007
Posts: 9


My Contributions
CODE
#include <iostream>
using namespace std;

int main()
{
    int row, col, stop;

    cout << "Enter a number between -9 and 9, excluding 0: ";
    cin >> stop;

    while ((stop < -9) || (stop > 9) || (stop == 0))
    {
        cout <<  "ERROR: Enter a number between -9 and 9, excluding 0: ";
        cin >> stop;
    }

    cout << "     ";
    for (int count = 1; count <= stop; count++)
    {
        cout << count << "  ";
    }

    cout << endl <<"   ";

    for (count = 1; count <= stop; count++)
    {
        cout << "---";
    }

    cout << endl;

    for (row = 1; row <= stop; row++)
    {
        cout << row << " | ";
        for (col = 1; col <= stop; col++)
            cout << (((row*col) < 10)?" ":"")
                 << row*col << " ";

        cout << endl;
        
    }

    return 0;
}


my problem is that when i put in positive 1-9 it lines up correctly and works, now we have to implement in neg numbers from -1 to -9 and i cant seem to get it to work. I have changed my for loops a thousand times and i think i am going the wrong way. can anyone point me in the right direction, when i put in aneg number it does nothing
i would really aprreciate the help.

I am trying to get this to print out the multiplication table as long as the entered in number is between -9 and 9, excluding zeros. It is suppose to be lined up like it is when i run the positive number on this code. It wont accept a neg number, when i put in the number and press enter, it says "press any key to continue"

This post has been edited by jayman9: 20 Mar, 2007 - 11:29 AM
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Multiplication Table
20 Mar, 2007 - 10:56 AM
Post #2

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
I am not sure what you are trying to do, but in order to count down in a for loop use.

print:
n, (n-1), (n-2), ... . 2, 1

for (count = n; count > 0;count--) { // stops at 1
cout << count << ", ";
}
cout <<endl;

using "count > -10" would stop at -9
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:58PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month