September 6th, 2003, 09:24 PM
Join Date: Aug 2003
Time spent in forums: 10 h 9 m 30 sec
Reputation Power: 11
Error checking function
Hi. i am writing a program that accepts 4 characters (cin>>a>>b>>c>>d) and then decodes the characters into a date format (integers). my problem is that after the characters are entered, i want to check to make sure that the person didn't enter any non-characters (ex. !@#$%1234...etc). i can't seem to get this to work because all of the characters have to be entered at one time. if their code is not correct, i want it to repeat the loop again. anyway, here is my code....
char chm,chfd,chsd,chy; //character values for month, first and second date digits and year
char answer; //declares answer as type char
int im,ifd,isd,iy; //integer values for characters
cout<<"Enter the four digit alphanumeric code (ex. AQQA) followed by ENTER: ";
chm = toupper(chm);
chfd = toupper(chfd);
chsd = toupper(chsd);
chy = toupper(chy);
cout<<"You entered the following alphanumeric code: "<<chm<<chfd<<chsd<<chy<<endl;
cout<<"Is this correct? (Y/N)";
answer = toupper(answer);
}while (answer == 'N');
im = int(chm) - 64; //calculates month value
ifd = int(chfd) - 81; //calculates first number in date
isd = int(chsd) - 81; //calculates second number in date
iy= ((int(chy) - 64) + 1990); //calculates year
if (ifd == 0 && isd == 0) //if the first and second digits of date are '0'
isd += 1; //increment second digit
if (im == 2 && ifd >= 2) //checks for 2nd month and higher than twenty days
if (isd == 9 || isd == 0 || isd == 1) //checks for higher than twenty eight days
ifd = 2;
isd = 8; //changes values to 28 days in feb.
cout<<"Your encrypted code produced the following date: "<<endl;
cout<< (im < 10 ? "0" : "")<<im<<"/"<<ifd<<isd<<"/"<<iy<<endl; //put '0' in front of months before 10
} //end of main function
Last edited by webblynx : September 6th, 2003 at 10:59 PM.