>How do I prevent the user from entering characters when a float is required?
There's no standard way to stop a user from entering a character. You'd have to use a non-portable solution or allow anything under the sun and provide robust validation. I always recommend going for the portable solution first, and fortunately, your case is easy to validate:
bool valid = false;
do {
cout<<"Please enter the CD cost: ";
if ( cin>> usrcost ) {
if ( usrcost > 0.0 )
valid = true;
}
else {
// Clear the error state
cin.clear();
// Clear the stream of all characters
cin.ignore ( 1024, '\n' );
}
} while ( !valid );