i am currently stuck on a problem with this program it works ok as far as the point of coins inserted, then it just keeps looping. any ideas?
i am currently stuck on a problem with this program it works ok as far as the point of coins inserted, then it just keeps looping. any ideas?
Last edited by dopecat; 04-10-2007 at 10:01 AM.
found it. In the future you should ask smarter questions than "debug this for me", but I was in a good mood.
you defined counter:
int counter = 0;
Then inside a while loop you increment it till it equals 5.
When this code runs for the second time, it's still 5 because it's defined outside the loop -
so the nested while loop won't run at all and thus is never checked if the name and pin match.
Solution: either define the counter inside the loop, or zero it before you check for the right pin:
>> counter = 0;
while (counter <= 4)
Note that you can omit the .h extensions of C++ standard headers, and a good compiler will warn you about that.
cheers mate, just got really annoyed looking at the code for the last few hours. thanks for
your help
I haven't tried to compile or test it, but the above doesn't look right (have no idea as to whether or not it has something to do with your loop problem.Code:if (coin != 0&&coin != 5&&coin != 10&&coin != 20&& coin != 50)
Is that suppose to read;
if(coin!=0&&coin || coin! = 5&&coin etc...)?
*edit, apparently that wasn't a problem. It still looks screwy to me though-
Actually, it took me only a couple of minutes;p
About what the old man here said: I'm curious too what it's supposed to do, if you want to explain this maybe I could help you make up a smarter if-condition, but if this just works for you, well...