Error for Multplication Table: numbers won't multiply right

This is a discussion on Error for Multplication Table: numbers won't multiply right within the C Programming forums, part of the General Programming Boards category; Hey guys so i produced a multiplication table; however the numbers don't multiply right ex 1 x 1 is not ...

  1. #1
    Registered User hungrymouth's Avatar
    Join Date
    Oct 2012
    Posts
    19

    Error for Multplication Table: numbers won't multiply right

    Hey guys so i produced a multiplication table; however the numbers don't multiply right ex 1 x 1 is not 2 and so on. Not sure where the error for this i want to make it so 1 x 1 = 1; 2 x 1 = 2; 3 x 1 = 3 and so on.

    Name:  lunapic_135466877699433_3.GIF
Views: 296
Size:  6.6 KB
    Code:
     // calling program
            
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "Myhead.h"
    #include "legrid.h" 
    
    int main()
    {
        Heading();
         
        ClearTheScreen();
       
        GridBox(3,3,13);
        
       
    
        PauseTheScreen();
    }
    // my header file

    Code:
    void ClearTheScreen()    
    {
        system("cls");
    }
    void PauseTheScreen()
    {
        _settextposition(45,24);
        _settextcolor(14);
        system("pause");
    }
    void Carpet(int Color)
    {
        int k,m;
        char Background[2];
        Background[0] = 176;
        Background[1] = '\0';
    
        _settextcolor(Color);
        for ( k = 0; k < 45; k++)
        {
            for ( m = 0; m < 80; m++)
            {
                _settextposition(k+1,m+1);
                _outtext(Background);
    
            }
        }
    
    }
    
    void Center(int Row,char *Text,int Color)
    {
        int k;
    
        _settextcolor(Color);
        k = strlen(Text);
        k = ( 80 - k ) / 2;
        _settextposition(Row,k);
        _outtext(Text);
    
    }
    void Heading()
    {
        ClearTheScreen();
        Carpet(10);
    
        Center(1,"VENTURA COUNTY COMMUNITY COLLEGE DISTRICT",14);
        Center(2,"Ventura College",14);
        Center(4,"Programming Fundamentals",13);
        Center(5,"CS V11 - Fall of 2012",13);
        Center(7,"Jessica Perez",12);
    
    }


    Code:
     // source code
    
    void GridBox(int Row,int Col,int Color)
    {
        int q,k,m,p;
    
        int ASCII;
        char Number[80];
    
        char UpperLeft[2],UpperRight[2],LowerLeft[2],LowerRight[2];
        char Vertical[2],Horizontal[2];
        char UpperTee[2],LowerTee[2],LeftTee[2],RightTee[2];
        char Cross[2];
    
        _settextcolor(Color);
                                                                             
        UpperLeft [0] = 218;
        UpperRight[0] = 191;
        LowerLeft [0] = 192;
        LowerRight[0] = 217;
        Vertical  [0] = 179;
        Horizontal[0] = 196;
    
        UpperTee[0] =   194;
        LowerTee[0] =   193;
        LeftTee [0] =   195;
        RightTee[0] =   180;
        Cross   [0] =   197;
    
    
        UpperLeft [1] = '\0';
        UpperRight[1] = '\0';
        LowerLeft [1] = '\0';
        LowerRight[1] = '\0';
        Vertical  [1] = '\0';
        Horizontal[1] = '\0';
    
         
        UpperTee  [1] = '\0';
        LowerTee  [1] = '\0';
        LeftTee   [1] = '\0';
        RightTee  [1] = '\0';
        Cross     [1] = '\0';
    
        // To print Numbers
    
        _settextcolor(14);
        for (m = 0; m < 5; m++)
        {
            for ( k = 0; k < 4; k++)
            {
                p = (k+1)*(m+1);
                itoa(p,Number,10 );
    
                if ( p < 10 )
                {
                    _settextposition(4+2*m, 8+2+4*k);//original 21+2+4*k
                }
            
                else if ( p < 100 )
                {
                    _settextposition(4+2*m, 8+1*k);
                }
            
                else
                {
                    _settextposition(4+2*m, 8+0+4*k);
                }
    
                _outtext(Number);
            }
    
        }
    
        for ( k = 0; k < 4; k++)
        {
            p = k+1;
            itoa( p,Number,10);
    
            if ( p < 10 )
            {
                _settextposition(6+2*k,6); //12 + 2, 19 original
            }
            else
            {
                _settextposition(6+2*k,7); //12 + 2, 18 original
            }
    
            _outtext(Number);
    
        }
    
    
    
    
    
        // CORNERS
        _settextposition(Row,Col);
        _outtext(UpperLeft);
        _settextposition(Row,Col+(3+1)*5);
        _outtext(UpperRight);
        _settextposition(Row+(1+1)*5,Col);
        _outtext(LowerLeft);
        _settextposition(Row+(1+1)*5,Col+(3+1)*5);
        _outtext(LowerRight);
    
        // Horizontal Lines
    
        for ( q = 0; q < 5 + 1 ; q++)
        {
    
           for ( k = 0; k < 5 ; k++)
           {
    
              for ( m = 0; m < 3 ; m++)
              {
           
                 _settextposition(Row+(1+1)*q,(Col+1)+(3+1)*k+m); 
                 _outtext(Horizontal);                            
              }
    
           }
        }
    
    
    
        // Vertical  Lines
    
        for ( q = 0; q < 5 + 1 ; q++)
        {
    
           for ( k = 0; k < 5 ; k++)
           {
    
              for ( m = 0; m < 1 ; m++)
              {
                 _settextposition((Row+1)+(1+1)*k+m,Col+(3+1)*q);
                 _outtext(Vertical);          
              }
           }
    
        }
        // Upper & LowerTee's
    
        for ( k = 0; k < 5 - 1 ; k++)
        {
           _settextposition(Row,Col+(3+1)*k+3+1);
           _outtext(UpperTee);          
    
           _settextposition(Row+(1+1)*5,Col+(3+1)*k+3+1);
           _outtext(LowerTee);
        }
    
        // Right & Left Tee's
    
        for ( k = 0; k < 5 - 1 ; k++)
        {
           _settextposition(Row+(1+1)*k+1+1,Col);
           _outtext(LeftTee);          
    
           _settextposition(Row+(1+1)*k+1+1,Col+(3+1)*5);
           _outtext(RightTee);
        }
    
        // Crosses
    
           for ( k = 0; k < 5 - 1 ; k++)
           {
    
              for ( m = 0; m < 5 - 1 ; m++)
              {
                 _settextposition(Row+(1+1)*k+1+1,Col+(3+1)*m+3+1);
                 _outtext(Cross);          
              }
           }
    }
    Last edited by hungrymouth; 12-04-2012 at 06:03 PM.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,434
    Hmm, without understanding the functions, and unable to run the code, it's difficult to say what might be going wrong.

    I might have an idea you can explore.

    It seems you want the following:

    - A 5x5 table
    - The first row contains header values 1 - 4
    - The first column contains header values 1 - 4
    - At each corresponding intersection of the table, you want to place the product of the row header times the column header
    * Therefore, the second row is where the products of the multiplication start

    However, what I suspect your code is actually doing is starting to place the products of the multiplication in the first row. 'm' and 'k' should both run from zero to three, but I see that 'm' runs zero to four - and afterwards, you print out the header column in the first column.

    Code:
    for (m = 0; m < 5; m++)
        {
            for ( k = 0; k < 4; k++)
            {
                p = (k+1)*(m+1);
                itoa(p,Number,10 );
     
                if ( p < 10 )
                {
                    _settextposition(4+2*m, 8+2+4*k);//original 21+2+4*k
                }
             
                else if ( p < 100 )
                {
                    _settextposition(4+2*m, 8+1*k);
                }
             
                else
                {
                    _settextposition(4+2*m, 8+0+4*k);
                }
     
                _outtext(Number);
            }
     
        }
    Do you think this might be the source of error?

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    I agree with the above statement as it looks like correct multiplication tables are placed in the boxes. But they are formatted one row higher than they should be. If you noticed your last row is all multiples of 5 rather than 4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [help]multplication table loop
    By amhiine24 in forum C Programming
    Replies: 32
    Last Post: 09-25-2011, 02:57 AM
  2. multiply arbitrarily large real numbers
    By Martin0027 in forum C Programming
    Replies: 7
    Last Post: 05-17-2011, 01:59 PM
  3. Replies: 15
    Last Post: 01-24-2008, 08:40 PM
  4. open file with numbers and multiply them
    By autopilot in forum C Programming
    Replies: 30
    Last Post: 09-10-2007, 04:48 PM
  5. How to multiply and Divide Huge int numbers
    By Dewayne in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21