a little help needed

This is a discussion on a little help needed within the C++ Programming forums, part of the General Programming Boards category; i am currently stuck on a problem with this program it works ok as far as the point of coins ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    Unhappy a little help needed

    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.

  2. #2
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    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)

  3. #3
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    Note that you can omit the .h extensions of C++ standard headers, and a good compiler will warn you about that.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    2
    cheers mate, just got really annoyed looking at the code for the last few hours. thanks for
    your help

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Code:
    if (coin != 0&&coin != 5&&coin != 10&&coin != 20&& coin != 50)
    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.

    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-

  6. #6
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    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...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. semi-colon - where is it needed
    By kes103 in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2003, 05:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21