简体   繁体   中英

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;
}
//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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM