Home > Back-end >  control reaches end of non-void function. How to solve this?
control reaches end of non-void function. How to solve this?

Time:09-04

solution.c: In function ‘subtractProductAndSum’ Line 31: Char 1: error: control reaches end of non-void function [-Werror=return-type] [solution.c] } ^ cc1: some warnings being treated as errors

int subtractProductAndSum(int n){

    int k , j=n , count=0 , add=0 , multiply=1;
  
    while(j>0){
    
        j=j/10;
        count  ;
    
    }

    int p=count;
    int arr[p];
        
    while(n>0){
        k=n;
        n=n/10;
        
        if(p>0){        
            arr[p-1]=k;
            p--;
        }
    }
    for(int i = 0; i <count ;i  ){
      add=add arr[i];
      multiply=multiply*arr[i];
    }
    
    int t=multiply-add;
    printf("%d", t);
    
}

CodePudding user response:

Your function is declared as an int, meaning it's expected to return an int. Your function doesn't return an int -- in fact, it doesn't return anything.

As @Retired Ninja said, you need to figure out what you want your function to return, and add an appropriate return statement.

  • Related