QUOTE(dexterandnoodles @ 24 Oct, 2006 - 12:05 PM)

well i'm trying to write this program to take a character input, then it needs to verify that it is first a number, then that it doesnt have multiple decimals (i.e. 34.54.34), and that the negative sign is in the right place if any. After that it should print out twice the inputed value. I can get it to do the last part, but its not validating for whatever reason. If i put in a letter it just says the number was 0. I had it validating once before, but it wouldnt accept digits (would say invalid data, like it should if a letter were entered), only letters.
anyway here's the code any help is greatly appreciated
Hi i have a little idea where to start...
The code is a little hard to read as you have a while inside a do/while.
basic code outline:
CODE
do
{
while( validData=true && i < len)
{
}
}while(validData = false );
you can see each loop relies on the same variable and they have opposing values... if you enter an invalid value and i >= len the loop will exit and then the outer loop exits too.
This suggests that something is actually changing valid to false and then you must exit the loop before you complete validation and conversion.
There is one lien of concern..
if (isdigit(myStr[30]))<<-- something is not quite right here
looking at your if statement
if (i == 0) when this is not true, you set
validData to
false... do I think you need to change the logic to:
CODE
for ( int i = 0; i < len; i++)
{
if ( ! isDigit ( myStr[i] )
validData = false;
}
this may need a little refining, but should get you back on track. I have reversed the logic you used as validData suggests its false when the data is not valid...
This post has been edited by gregoryH: 25 Oct, 2006 - 02:55 AM