My problem has been fixed thankyou
Printable View
My problem has been fixed thankyou
> while (iAgeError = 1);
Use == for comparison.
:D rookie mistake! thanks Salem!
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?
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
after "printf ("Valid number: %ld.\n", iAge);" you need to put "iAgeError=0".
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!!!