MISCUE!! How do I do this????

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zumina
    What Are You Looking At?
    • Jan 2001
    • 2081

    #1

    MISCUE!! How do I do this????

    I need to write a program hat prints the following multiplication table using while loops; and no if statements:

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

    I'm stumped! My while loops produce garble; as they only carry out the first two numbers.....please please enlighten me!
    Shoot it like you stole it!
  • Zumina
    What Are You Looking At?
    • Jan 2001
    • 2081

    #2
    bump
    Shoot it like you stole it!

    Comment

    • subbeh
      I'm Not Cool
      • Jan 2002
      • 821

      #3
      In C++ ? VB ?

      I Might be able to help.
      Subbeh

      "My wife might find my stashed Marker Money before then, and then boom-new patio furniture or some other garbage."
      -1stDeadEye

      Comment

      • MantisMag
        Dim Sum
        • Dec 2001
        • 1895

        #4
        int row=1;
        int column=1;
        while (row<10)
        {
        column=1;
        while(column<=row)
        {
        cout << row*column << " ";
        column++;
        }
        cout << endl;
        row++;
        }

        that's in c++. pretty sure it works. try it. oh doesn't print out your 1-9 at the side and bottom though. just noticed that. if you can't figure that out you don't belong in computer science.

        Comment

        • Miscue
          Super Moderator

          • Oct 2000
          • 7105

          #5
          #include < iostream.h >

          #define MAXTABLE 9

          int main()
          {

          cout << " ";
          for (int i = 1; i <= MAXTABLE; i++)
          cout << i << ' ';
          cout << endl;

          for (int j = 1; j <= MAXTABLE; j++)
          {
          cout << j << ' ';
          for (int i = 1; i <= j; i++)
          cout << i * j << ' ';
          cout << endl;
          }

          return 0;
          }

          I just noticed you wanted while loops. Same thing really, just create a for-loop using while.

          Comment

          • Zumina
            What Are You Looking At?
            • Jan 2001
            • 2081

            #6
            Thanks Guys!!!! *bows head in the presence of computer gurus*
            Shoot it like you stole it!

            Comment

            • Zumina
              What Are You Looking At?
              • Jan 2001
              • 2081

              #7
              wait a minute....no For loops allowed!!
              this is funky:

              code:


              #include <iostream.h>

              int main(void)
              {

              int row=1;
              int column=1;
              int test = 1;

              cout<<" 1 2 3 4 5 6 7 8 9" << endl; //yah, I'll add some iomanip late
              while (row<10)
              {

              column=1;
              while(column<=row)

              {
              cout << row*column << " ";
              column++;
              }

              cout << test <<" "<< row <<" "<< column << endl;
              row++;
              test++;
              }

              return 0;

              }

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

              grrrrr!
              Last edited by Zumina; 02-28-2002, 07:09 PM.
              Shoot it like you stole it!

              Comment

              • Zumina
                What Are You Looking At?
                • Jan 2001
                • 2081

                #8
                1
                22
                111
                2222
                00000
                1 1 1 2
                2 4 2 2 3
                3 6 9 3 3 4
                4 8 12 16 4 4 5
                5 10 15 20 25 5 5 6
                6 12 18 24 30 36 6 6 7
                7 14 21 28 35 42 49 7 7 8
                8 16 24 32 40 48 56 64 8 8 9
                9 18 27 36 45 54 63 72 81 9 9 10
                1111111111111
                1111111111111
                1111111111111
                1111111111111
                1111111111111
                1111111111111

                up!
                Shoot it like you stole it!

                Comment

                • gimp
                  Registered User
                  • Jan 2001
                  • 2368

                  #9
                  to change the for loop to a while loop, just do something like this:
                  j=MAXTABLE;
                  while(j>=1){
                  blah
                  blah
                  blah
                  j--;}

                  Comment

                  • Zumina
                    What Are You Looking At?
                    • Jan 2001
                    • 2081

                    #10
                    what is this maxtable business?
                    Shoot it like you stole it!

                    Comment

                    • MantisMag
                      Dim Sum
                      • Dec 2001
                      • 1895

                      #11
                      what's with that test? that cout statement is all screwy. MAXTABLE is just a constant. although i was told that doing it that way was bad style. shouldn't use define cause that's c not c++. i'm gonna help you out here and fix your code. i don't know what the hell you were thinking with that test thing.

                      #include <iostream.h>

                      void main()
                      {
                      int row=1;
                      int column=1;

                      cout<<" 1 2 3 4 5 6 7 8 9" << endl; //yah, I'll add some iomanip late
                      while (row<10)
                      {

                      column=1;
                      cout << row << " ";
                      while(column<=row)

                      {
                      cout << row*column << " ";
                      column++;
                      }
                      cout << endl;
                      row++;
                      }
                      }

                      i even compiled it and ran it and got this output:
                      1 2 3 4 5 6 7 8 9
                      1 1
                      2 2 4
                      3 3 6 9
                      4 4 8 12 16
                      5 5 10 15 20 25
                      6 6 12 18 24 30 36
                      7 7 14 21 28 35 42 49
                      8 8 16 24 32 40 48 56 64
                      9 9 18 27 36 45 54 63 72 81
                      Press any key to continue

                      ok? got it? any questions now? like i said i have no idea what you were thinking with that whole test thing. that cout screwed everything up.

                      Comment

                      • Zumina
                        What Are You Looking At?
                        • Jan 2001
                        • 2081

                        #12
                        doh! Why, why are the answers so painfully obvious? Gimp, thank you SOOO much! I apreciate it. Sorry for looking like a C++ fool, but I'm just starting and I've never really understood while loops and such; until now. Thanks man!
                        Shoot it like you stole it!

                        Comment

                        Working...