I am running into errors when I am compiling code in CodeBlocks, and I am not sure what I am doing wrong. I am creating this simple program for a class, but it is pulling up an error saying on line 27 (I have bolded it in the code): "error: expected primary-expression before 'float' for all 3 variables. Someone help me with this? I'm completely lost.
That's not the correct syntax for calling a function. I strongly recommend you go back to your textbook and learn how to call a function properly, because it's absolutely fundamental to being able to program.
I guess I'm very confused then because in my instructor's sample code, "float mileage" was called before main. I'm going to have to read this textbook again.
I just didn't understand what he was doing by declaring a variable like that up above main. I couldn't see what he wanted to do with it, so I just removed the mileage variable and set the mpg to what mileage would have been.
Well, it looks like it'll work fine, although it no longer calls a function to do the calculation. If the purpose of the exercise was to learn about functions, then it's probably not much use now ;)
I just didn't understand what he was doing by declaring a variable like that up above main. I couldn't see what he wanted to do with it, so I just removed the mileage variable and set the mpg to what mileage would have been.
mileage isn't a variable - it's a function. That bit above main is declaring a function called mileage, and declaring which arguments it takes and what it returns.