Blake McCorkle
Blake McCorkle

Reputation: 9

expected a ';' - I've copied this code from a learning resource and it doesn't work

I'm having trouble with the syntax of my prototyping and implementation of function. The first bracket { right below my function's implementation keeps throwing an error saying:

expected a ';'

I am literally copying and pasting this code from this learning resource here because I assumed they would have no errors. Is this something super simple that I am missing? I have tried rebuilding, taking a break and coming back, starting a brand new project and copying/pasting it again from the web page. Adding a semicolon just breaks the function in other ways as expected. I'm using VS 2015.

int main() {

    double someFunction(double, int);

    double someFunction(double x, int y)
    {  
        return x * y;
    }
    return 0;
}

Upvotes: 0

Views: 63

Answers (1)

user3853544
user3853544

Reputation: 583

//Prototype  
double someFunction(double, int);

//Main 
int main() {
    //calling your function
    someFunction(0.5,2);

    return 0; 
}

//Function definition
double someFunction(double x, int y)
{  
    return x * y;
}

Should be like this.

Upvotes: 2

Related Questions