Hi everyone i have a IF() with two counters but it is not incrementing... ignore the couts they are there to troubleshoot the loop. The characters im feeding through data is ##ss which should return a false because there is more then one s but the counter does not remember. Please if anyone can help it would be much appreciated.
Thanks
bool isValid(char data)
{
int sCount=0;
int fCount=0;
if (data=='#'||data=='s'||data=='f'||data==' '||data=='\n') {
if (data=='#'||data==' '||data=='\n'){
cout <<"char is" <<' '<< data <<' '<<"line\n";
return true;
}
else if (data=='s'&&sCount<2){
++sCount;
cout << "char is "<<data<<" ocurring"<<sCount<<"\n";
return true;
}
else if (data=='f'&&fCount<2){
fCount++;
cout << "char is f\n"<<fCount;
return true;
}
}
else {
return false;
}
}
Your variables are reset every time you run the function. To get around this, define them outside of all the functions (firedraco, if you're reading this, global variables are evil only in larger programs. :D).