Hello. Recently I have started to learn C++, however I ran into some problems. First of all, take a look at this part of code:
while (Uncomplete) {
if(counter > 8) draw = true;
if(draw == true) {
PlaceCursor(0, 10);
cout << "Its a draw!\n" << "continue?";
getch();
Uncomplete = false; }
counter++;
}
Obviously its just part of my code. I'm not sure why, but "if(counter > 8) draw = true;" activates every loop, even if counter is equal to 0. I have tried inserting cout << "counter"; to my code, and it shows Counter = 1, but the "If" still actives... What could be the problem?
Secondly... how do you return several values with a function?
return val1, val2;
Doesn't seem to work...
Also, what is a good way to initialize a variable in a function, just once? For example my function starts multiple times:
Func() {
bool var1 = true;
if(Globalvar1 == 1) var1 = false;
}
So, if I start this function, and Globalvar1 isnt equal to 1, then var1 turns to true even though I want it to stay false. I thought about using static variables, but that didn't work.
And the last question, how do you force an exit out of several loops?
For example:
bool Once = true;
for( ; ; ) {
for( ; ;) {
if(SomeVar1 == true) {
cout << "cakes!"
break;
}
}
}
This would break only the if statement, but not the two For's.
Thanks in advance!