How do I prevent the user from entering characters when a float is required? I'm using a bool for valid entry so if they enter text it sends my loop running
henpecked1
0
Posting Whiz in Training
Recommended Answers
Jump to Postafter using cin call peek() to see if the next character is '\n' or not.
int x; cin >> x; if( cin.peek() != '\n') cout << "Bad\n";
Or get it as a string and check each character.
All 4 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
henpecked1
0
Posting Whiz in Training
Narue
5,707
Bad Cop
Team Colleague
henpecked1
0
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.