Error: identifier or '(' before '{' token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ZS369
    New Member
    • Aug 2018
    • 8

    Error: identifier or '(' before '{' token

    Q: Error: identifier or '(' before '{' token

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    float convertToEuro(float sek);
    
    int main()
    
    {
       float sek, euro, result;
       printf("Mata in antal svenska kronor: \n");
       scanf("%f", &sek);
       result = convertToEuro(sek);
       printf("%.2f kronor motsvarar %.2f Euro", sek, result);
       return 0;
    }
    
       float convertToEuro(float sek);
    {
        float euro = sek * 0.095;
        return euro;
    }
    Last edited by zmbd; Aug 19 '18, 09:27 PM. Reason: [z{placed question within body of post}{Please format code/script using the [CODE/] formatting tool}]
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    You have put a semicolon just before the definition of function body which literally means the function has no body.

    That is required only in the declaration of function as it tells the compiler the function name, return type and the no. and types of arguments.
    Code:
    # Preprocessor directives
    
    //Function declaration
    return-type name(number and types of arguments);
    
    main(){
     body of main
    }
    
    //function definition
    return-type name (arguments details){
    function body
    }
    However if the function is defined before the main function, there is no need of declaration.
    Last edited by zmbd; Aug 19 '18, 09:28 PM. Reason: [Z{Please format code/script using the [CODE/] formatting tool}]

    Comment

    Working...