if i enter no numerical chars a cin error occursCode:... int choice; cin >> choice; ...
that i can't restore with cin.clear()
i detect the error with cin.fail()
is it a fatal error?
TIA
if i enter no numerical chars a cin error occursCode:... int choice; cin >> choice; ...
that i can't restore with cin.clear()
i detect the error with cin.fail()
is it a fatal error?
TIA
to boldy code where...
Try something like this one:
Code:#include <iostream> int main() { int i; std::cout <<"Enter a number" <<std::endl; while (!(std::cin>>i)) { std::cout <<"Again:" <<std::endl; std::cin.clear(); while (std::cin.get() != '\n'); } std::cout <<"You entered " <<i <<std::endl; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
or take out all the std:: and putat the beginingCode:using namespace std;
.. and for those interested, you can learn a little more about namespaces here
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]