0

Hey, i saw this thread about some one needing homework help but it was solved so i made one and it's not real homework but i was wondering how i could do something if the user entered a letter eg "e".

#include <iostream>
using namespace std;

int main()
{
    int dollarAmmount;
    
    cout << "Enter A Dollar Ammount Between $0 & $100" << endl;
    
    cout << "$";
    cin >> dollarAmmount;
    
    if (dollarAmmount < 0)
    cout << "ERROR : Dollar Ammount Is To Low.";
    
    if (dollarAmmount > 100)
    cout << "ERROR : Dollar Ammount Is To High.";
    
    else
    cout << "Thanks.";
    
    system("PAUSE>nul");
}

Like.. to make it have a error like "ERROR : Input Is Not A Digit."

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

when you enter a non-digit cin will set the error flag so all you have to do is test for it

if( cin.error() )
{
   cout << "ERROR ...";
   cin.clear(); // clear the error flag
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.