My problem has been fixed thankyou
My problem has been fixed thankyou
Last edited by Astra; 10-21-2006 at 05:50 PM.
> while (iAgeError = 1);
Use == for comparison.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
rookie mistake! thanks Salem!
Last edited by Astra; 10-21-2006 at 10:59 AM.
Okay i've changed it to == now on the final while statement.
It works when i input a string of numbers, and exits the loop and program.
HOWEVER! (dun dun dun..) If i enter an invalid number (ie. x) it says Invalid Number and asks me again (correct)
but when i now input a number, it says Valid Number but asks me again! (when it should exit the program)
Help me! I am assuming it is because the invalid value is still in the stream?
Last edited by Astra; 10-21-2006 at 11:02 AM.
You need to set your valid flag to 0 when you detect success.Code:$ gcc -W -Wall -ansi -pedantic -O2 new.c new.c: In function `main': new.c:6: warning: 'iAgeError' might be used uninitialized in this function
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
after "printf ("Valid number: %ld.\n", iAge);" you need to put "iAgeError=0".
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Thanks, both of you!! I can finally make my program now, using this system of repeating do while's and checking for errors! You have saved my life by helping me learn this!!!