Okay, I have been trying to figure this out for a week now just by looking up online. Now I have to ask for your help.
I am trying to verify that the price I have are all numbers with the decimal in the 5th position, i.e. 2435.12. I can't seem to get this thing to read the non numeric digit as a non numeric digit. Here is my code:
//assume correct entry
char errorPrice = 'n';
//get the length of the string
int length = Price.length() - 1; //ignore the terminating character
if(Price[length-3] != '.') //check the position from the right isn't equal to '.'
errorPrice = 'y';
question i have for you is why store price like this? Keep it as a double and format the output.
I am getting the string "1100./0" from an external file. I am using the getline to read it. Then I am using the errorPrice variable to make a decision in my main to either input the record or put out an error message and reject that line.
I'm using the ascii codes here. What i'm doing is casting the value of the character as an integer and checking if the value is within the range of the ascii equivalent. if ti is, i continue. If it isn't no need to go on, the number is not valid.