1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int main()
{
float squareFeet;
float paintCost;
float labCost;
float totCost;
printDescription();
squareFeet = getSquareFeet();
paintCost= cost();
labCost= labor(sFeet);
totCost= total(paint, laborCost); //What is "paint" - should you be using "paintCost"?
printValue(sFeet, paint, laborCost, total); //what is "sFeet"? Should you be using "squareFeet"? Same goes for "paint" and "total"
}
|
Because you're executing in main, your program will look for those variables in main. sFeet and paint and total weren't declared in main, so your program can't find them. Those variables exist inside the other functions you wrote, but only within the scope of those functions. It looks like you should be using
paintCost
,
squareFeet
and
totCost
in place of
paint
,
sFeet
and
total
inside of your main when you are calling
labor(...)
,
total(...)
and
printValue(...)
Just remember that variables are within scope only in the area they are declared. Unless they are global, variables will be visible only within the functions they are originally declared in. Moreover, variables declared within loops inside of a function will only be visible within that loop.
In other news, don't let the rudeness of the other commenter get to you. It's people like that who almost drove me away from programming. I'd ask a question, get called "stupid" and "lazy" and told to f off. Most of us aren't like that. You posted your code, and you posted the errors, which a lot of people here don't even bother to do. But, we usually do prefer it if you use the "code" tags. There is a "<>" button in the formatting options, and it will format the text in-between to look like code. It just makes it much nicer to look at.
I have to congratulate you. Not bothering to tell us what lines the errors are on is quite a usual occurrence, but you went better than that, and actually told us the wrong lines. Spectacular! |
I don't think I've seen a comment that rude in quite a while. If you're pissed about a post, ignore it. There's absolutely no need to come in here and bash the original poster.
Meh. I'm sick of lazy, rude people coming in here, making absolutely minimal effort to give us the information that would be helpful |
OP DID give the information. The error codes included what was wrong on the lines. We, as programmers, should be able to figure out the location even if the line numbers don't match up.
I apologize for MikeyBoy's rudeness. That was far from a "gently reprimand". Most of us aren't like that.
We're always happy to help. Feel free to post your questions. The more information you give us, like error codes, error descriptions, line numbers, etc, the easier it will be for us to help you debug your code.
Happy programming!