I am having trouble with the "for loop" of a 32 bit Adder program. I am suppose to take 2 arrays of 32 bits and sum them together.

The 2 errors I get are on line 37 and 38 called "called object is not in function".

I don't know how to implement the for loop. Can anyone help or point me in the right direction?

#include "stdio.h"
#include "stdlib.h"


int sum(int x[], int y[], int c);
int carryIn(int d[], int e[], int f);

int main (void){
    
    int a[32], b[32], sum[32];
    int x,y,c;
    int d,e,f;
    int i;

    printf("Enter 32 bits: ");
    scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", 
    &a[31], &a[30], &a[29], &a[28], 
    &a[27], &a[26], &a[25], &a[24], &a[23], &a[22], &a[21], &a[20], &a[19], &a[18], &a[17], 
    &a[16], &a[15], &a[14], &a[13], &a[12], &a[11], &a[10], &a[9], &a[8], &a[7], 
    &a[6], &a[5], &a[4], &a[3], &a[2], &a[1], &a[0] );
    
    printf("Enter 32 bits: ");
    scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", 
    &b[31], &b[30], &b[29], &b[28], 
    &b[27], &b[26], &b[25], &b[24], &b[23], &b[22], &b[21], &b[20], &b[19], &b[18], &b[17], 
    &b[16], &b[15], &b[14], &b[13], &b[12], &b[11], &b[10], &b[9], &b[8], &b[7], 
    &b[6], &b[5], &b[4], &b[3], &b[2], &b[1], &b[0] );
    
    
      int carryIn=0;   //Initialize 0 to carryIn
      
     for(i=0;i<32;i++){
    
      sum(a[i],b[i],carryIn); //compute the sum
     carry(a[i],b[i],carryIn); // compute the carryover
     
     sum[i]= sum(a[i],b[i],carryIn);  //put sum in the sum[] array
     carryIn = carry(a[i],b[i],carryIn);
                
                       }
    
    system("PAUSE");
    return 0;
} 
    int sum(int x[], int y[], int c){
        
        return ((!x && !y && c)||
               (!x && y && !c) ||
               (x && !y && !c) ||
               (x && y && c));
    }
    
    int carry(int d[], int e[], int f){
        
        return ((!d && e && f) || 
                (d && !e && f) ||
                (d && e && !f) ||
                (d && e && f));
    }

search for the token 'sum'. You will see that you have used it as the name of a function and also as the name of an array (lines 5 and 10).

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.