better yet, just clean up your code with a single function:
Code:
bool isNumber( char str[] )
{
char *s;
for( s = str; *s; s++ )
if( !isdigit(*s) && *s != '.' )
retrurn false;
return true;
}
That would let you do just:
Code:
cout << endl << " You entered option 3" << endl << endl;
system("pause");
do{
system("cls");
cout << endl << " Please enter a price: $";
cin >> itemPrice1;
if( !isNumber ( itemPrice1 ) )
{
system("cls");
cout << endl << " Please enter a price only!";
cout << endl << " Please enter a price: $";
cin >> itemPrice1;
index = 0;
}
else break;
} while( 1 ); //...infinate loop...
double x;
x = atof( itemPrice1 );
cout << setprecision(2) << x;