Hi,

Im trying to make a multiply table from 1 to 10.

Im trying to do this with array's.

This is the code i have till now:

#include "conio.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <cmath>

#define arraylen = 10

main()
{
     int x[11], *a;
     int y[11], *b;
     
     int answer = ( (*a) *  (*b) );
     int input; 
     a = &x[11];
     b = &y[11];
     
     for( int i = 1; i < a; i++ )
     {
          for( int j = 1; j < y; j++ )
          {
               printf( "%i * %i = " , x, y );
               scanf( "%i", &answer );
               
               if( answer != x * y )
               {    
                   printf( "WRONG ANSWER !" );
               }
               
               else
               {
                   printf( "GOOD ANSWER !" );
               }
          }    
     }          
     printf( "\n" );
     system( "pause" );
}

These are the errors i get:

22 ISO C++ forbids comparison between pointer and integer

22 ISO C++ forbids comparison between pointer and integer

27 invalid operands of types `int[11]' and `int[11]' to binary `operator*'


Thnx in advance!

Hi,

Try this :

main()
{
     int answer;
     int input; 

     for( int i = 1; i < 11; i++ )
          for( int j = 1; j < 11; j++ )
          {
               printf( "%i * %i = " , i, j );
               scanf( "%i", &answer );

               if( answer != (i * j) ) printf( "WRONG ANSWER !" );
               else printf( "GOOD ANSWER !" );
          }    
     printf( "\n" );
}

I just cleared what is unnecessary.
Loren Soth

>> int answer = ( (*a) * (*b) );
what is the intent of ^^^ that line? variables a and b are used before they are initialized and will surely cause your program to crash. Just simply code it like this:

int answer;

>> a = &x[11];
that ^^^ is setting variable a to point to an element of x that is beyond the end of the array. array indices in your example are numbered 0 to 10. So if you want variable a to point to the last element of x, then it should be like this

a = &x[10];

But if you want variable a to point to the first element of x, then do this

// the following two lines do the same thing.
a = x;
a = &x[0];

>> for( int i = 1; i < a; i++ )
Variable a is a pointer -- why would you want to use a pointer like that?

>> for( int j = 1; j < y; j++ )
variable y is an array of integers. and you can't use the name of an array in an expression like that.

>> int answer = ( (*a) * (*b) );
what is the intent of ^^^ that line? variables a and b are used before they are initialized and will surely cause your program to crash. Just simply code it like this:

int answer;

>> a = &x[11];
that ^^^ is setting variable a to point to an element of x that is beyond the end of the array. array indices in your example are numbered 0 to 10. So if you want variable a to point to the last element of x, then it should be like this

a = &x[10];

But if you want variable a to point to the first element of x, then do this

// the following two lines do the same thing.
a = x;
a = &x[0];

>> for( int i = 1; i < a; i++ )
Variable a is a pointer -- why would you want to use a pointer like that?

>> for( int j = 1; j < y; j++ )
variable y is an array of integers. and you can't use the name of an array in an expression like that.

I've tried a few things which also didn't work. This was the last thing i tried.

I was looking for the last example you gave me.

Thnx !

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.