Hi All,
I have a question about values in arrays.
My array values seem to be “magically” changing as they move through this function…
witchOrNot[0] = 0;
strawPoked[0] = 0;
drawStrawberry[0] = 0;
//strawberry1:
if((ard.getDigital(3)) == 1){
cout << "Witch or not: " << witchOrNot[0] << endl;
if(strawPoked[0] == 0){ //means if strawberry 1 has not been poked yet
strawPoked[0] = 1;
cout << "Straw1 poked: " << strawPoked[0] << endl;
//at this point, witchOrNot[0]'s value has changed from 0 to 1>>>>WHY?!??!
cout << "wicthOrNot[0] AfterPoked: " << witchOrNot[0] << endl;
if(witchOrNot[0] == 1){ //means if strawberry1 IS a witch
witchOrNot[0] = 2;
witchCounter = witchCounter + 1;
drawStrawberry[0] = 3;
isAWitchSounds();
cout << "drawStrawberry[0] inside of fcn 1: " << drawStrawberry[0] << endl;
cout << "witch count after Straw1 poked: " << witchCounter << endl;
}
else if(witchOrNot[0] == 0){ //means if strawberry1 is NOT a witch
witchOrNot[0] = 3;
drawStrawberry[0] = 2;
witchCounter = witchCounter;
notAWitchSounds();
cout << "drawStrawberry[0] inside of fcn 2: " << drawStrawberry[0] << endl;
cout << "witch count after Straw1 poked: " << witchCounter << endl;
}
}
//somehow strawPoked has magically changed from a value of 1 to a value of 3 here:
cout << "Has Strawberry 1 been poked? " << strawPoked[0] << endl;
}
My console Reads:
Witch or not: 0
Straw1 poked: 1
wicthOrNot[0] AfterPoked: 1
drawStrawberry[0] inside of fcn 1: 3
witch count after Straw1 poked: 1
Has Strawberry 1 been poked? 3
witchOrNot outside of fcn: 3/0/1
drawStrawberry outside of fcn: 3-0-1
witchCounter outside of fcn: 1
What I have noticed, as the console and comments suggest, is that the array values are changing through the function. Does this have something to do with pointers or some other C++ concept that I am totally missing here?
Thank you very much for any replies or help. Let me know if you need more info.
~VeeBee