Cannot convert float to float

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roverzon
    New Member
    • Jul 2012
    • 2

    #1

    Cannot convert float to float

    The compiler shows the error of cannot convert float to float at line 1.

    I don't know what's going on about this error.

    It is an easy program for calculating a distance between two point




    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    void Distance(float p1[],float p2[]); 
    
    int main(){
        float p1[3] = { 0, 0 ,0 };     
        float p2[3] = { 3, 4 ,0 };
        float dis;  
        
        dis = Distance(p1,p2); 
        
        printf("%f", dis); 
        
        system("pause"); 
        return 0; 
    }
    
    void Distance(float p1[],float p2[]){
        float delta[3] ={0};
        float del_square =0;  
               
        for (int i = 0; i < 3; i++){
            delta[i] = p1[i] - p2[i]; 
        }
        
        for(int i = 0; i < 3; i++){
            del_square += delta[i] * delta[i]; 
        } 
        
        return sqrt(del_square); 
    }
    Last edited by weaknessforcats; Jul 11 '12, 05:52 AM. Reason: added code tags
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This code:

    Code:
    dis = Distance(p1,p2);
    assigns the return value from Distance to dis. But Distance returns a void (which means it returns nothing). So the complier complains it cannot convert void to float.

    Also please use code tags.

    Comment

    Working...