![]() |
do while prob on validation
Hey guys my while condition isnt working working properly in validateMonth what happens it just stays in there. If i type in 5 or any number between 0-12 it will still say its the wrong input. Why isnt it testing the condition properly?
Code:
unsigned getMonth()Code:
unsigned validateMonth(unsigned month, char *prompt) |
Re: do while prob on validation
I have lots of queries for your validateMonth function.
1. Why do you need do while and while loops at all. 2. Its always an infinite loop because you have FLAG = FALSE as initial values and then you have an OR condition. 3. You have never assigned FLAG as true but then also testing that almost in 2 while and do while loops. 4. You are returning m which is not used in the function and so the return value is always a garbage. Cant it be done as Code: C
|
Re: do while prob on validation
iv got the while loops so that if it is an error i want it to re get the user input
|
Re: do while prob on validation
iv used that and it still dosnt test the condition properly .... i enter for example 5 which is between
0-12 and it still falls inside the if and says "month error 0 or less then equal to 12" then i type it a second type and it works.. why is that? |
Re: do while prob on validation
Quote:
|
Re: do while prob on validation
Quote:
Code: C
|
Re: do while prob on validation
Should i be testing for the result variable instead inside the validation function rather then the "month" variable?
Is that what u mean by the different variable? |
Re: do while prob on validation
No what I meant is you are inputing the value 5 in one variable and testing it in other.
|
Re: do while prob on validation
im lost completely sorry .... its something simple but i dont get what your trying to say?
|
Re: do while prob on validation
What he is trying to say is
You are taking the input from the user in the variable month which is a local variable in getMonth function. month = getUserInput(prompt); Then you are calling the validate month function with valMonth another variable which is never initialized as tmpMonth = validateMonth(valMonth, prompt); Then valMonth is always has a grabage value. How do you expect it to validate the input taken from the getUserInput function. Thanks Shabbir |
| All times are GMT +5.5. The time now is 05:32. |