Hi, my code follows asks to enter the pin number,if it matches with the database pin number, it will proceed.otherwise it will tell wrong pin number.now i need my code to ask the pin number three times if it is wrong.i have used while loop.but i dont know where to place the loop exactly.Even this is simple,please help me to solve this.
the above code comes to while if pin is wrong and it is not terminating even if i give the correct pin number second time.please guide where to put the while loop.otherwise i have to use for loop for this?
This is the only occasion where you get the pin number. What happens if the pin number is wrong the first time? You do not retrieve it when it fails validation.
the above code comes to while if pin is wrong and it is not terminating even if i give the correct pin number second time.please guide where to put the while loop.otherwise i have to use for loop for this?
Not sure what you meant by "it is not terminating". Do you see that your while loop simply counts up till it reaches 2 and then leaves? You have to try and get the pin number and perform validation to see if it is correct.
So, yes -- you have to rewrite your code, and you may be better off doing a do-while loop since you have to get the pin number and validate it at least once.
- Anand
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
preethi Ayyappan
Ranch Hand
Joined: Oct 04, 2007
Posts: 518
posted
0
thanks for your replies.i have tried like this.but it is also not working correctly.
Anyone please help me by modifying the code to work fine. [ March 06, 2008: Message edited by: preethi Ayyappan ]
It would help if you clarify what you mean by "not working correctly". Also, to quote Jerry Maguire, you would be helping us help you if you indent your code and make it more readable (get rid of tabs when you copy-paste).
In any case, try changing your else condition from - - to simply - (both the checks in the else clause are redundant). That may or may not resolve your problem, because am not sure what exactly it is.
Anyone please help me by modifying the code to work fine.
That's not what we do here. We're happy to help you, guide you, answer your questions, and so forth.
We do NOT write code for you. Please don't ask again.
Never ascribe to malice that which can be adequately explained by stupidity.
Gavin Tranter
Ranch Hand
Joined: Jan 01, 2007
Posts: 333
posted
0
I agree, that a do while loop is porobably the best way to go here. If the input is correct you do the requried work if it fails you go around the loop, if its the final attempt and it fails you do the error conditions.
Its always a good idea to think about what you are attempting to do, and then use some "design" notation to work out the details, for small problems pseudo code often helps, something like: