mercredi 4 mars 2015

Simulated Check, Error when checking user inputted amount. c++


I have a program written that prints out a simulated paycheck. Everything is okay according to my teacher's standards except my loop checking the amount the user entered. I get the amount the user entered and put it into a string. I then convert that into an int to check if it is within the bounds of 0-10,000. It either skips that check completely or the program crashes. Any idea why? It is in the getInfo function. I have to bring the amount in as a string. I will also eventually have to to this with string class objects as well. Also my spacing is better on in codeblocks. I never get it entered right here. Thanks!



void getInfo(int nameS, int dateS, int amountS, char name[],char date[], char check[])
{


cout<< "Please enter the name of the recipient: ";
cin.getline(name, nameS);


cout<< "Please enter the date EX. mm/dd/yy: ";
cin.getline(date, dateS);
do
{


if(strlen(date)!= 8)
{
cout<< "That was not the correct date format. Please Enter again. Ex. mm/dd/yy";
cin.getline(date, dateS);
}

} while(strlen(date)!= 8);
// Small check for the right size. Does not check for character.






cout<< "Please enter the amount: above zero and under 10,000: ";
cin.getline(check, amountS);
double quickCheck=atof(check);


//PROBLEM
do{
if(quickCheck>10,000 || quickCheck<0)
{



cout<<"That amount is not within the bounds. Please enter again.";
cin.getline(check,amountS);


}



} while(atoi(check)>10,000 || atoi(check)<0);






return;


}



Aucun commentaire:

Enregistrer un commentaire