dimanche 26 septembre 2021

expected expression before 'float'

I keep getting the same error for line 39, I'm new to programming and I'm trying to familiarize myself with function calls so I'm assuming that the error might be something to do with the syntax I'm using to call the function but I have no idea what it is. The function is called 'calculatecharges' and the function is supposed to receive an array of floats and return nothing.

# include <stdio.h>

void calculatecharges(float hours[]){
    float charge[3];
    float hourst=0.0;
    float charget=0.0;
    int count=1;
    
    for(int i=0;i<=2;i++){
        if (3>=hours[i]>0){
            charge[i]=2;
        }else if(3<hours[i]<=23){
            charge[i]=(2+((hours[i]-3)*0.5));
        }else if(hours[i]==24.0){
            charge[i]=10;
        }
    }

    for(int j=2;j>=0;j--){
        hourst=hourst+hours[j];
        charget=charget+charge[j];
    }
    printf("Car         Hours                Charge\n");
        for(int looper=0;looper<=2;looper++){
            printf("%d           %f             %f\n",count,hours[looper],charge[looper]);
            count+=1;
        }
        printf("Total       %f         %f",hourst,charget);
    
}

int main(){
    float hours[3];
    float charge[3];
    
    printf("Enter the number of hours the 3 cars stayed(seperate numbers with a comma): ");
    scanf("%f,%f,%f",&hours[0],&hours[1],&hours[2]);
    
    calculatecharges(float hours[]);
  
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire