Hey, I have a quick question. When I try to compile this program that has a global variable declared at the beginning, the variable works in all cases except when used in a for loop. It comes up as "variable counter undeclared". What can I do to fix this? (And don't tell me global variables are evil, I'm supposed to use them for this assignment)
int counter;
int main()
{
for(counter=0;counter<45;counter++)
etc etc
}
int function()
{
for(counter=0;counter<20;counter++)
etc etc
}
1. Why would you do something like that ? It's irrelevant and confuses
2. Code should be written in such a manner that it is easier for humans and optimized for machine . So this way of writing things is weird , I guess
I figured out the problem. I was using the word "count" instead of "counter" which for some reason I guess is a word we're not allowed to use as a variable name. Oh well
If somewhere you wrote "using namespace std;" you should know that that there is a function std::count that you are bringing into the global namespace.