Friday, 20 February 2015

how we can avoid char input for int variable

if we put char in int in c++ or c then programm will crash so
how we can avoid char input for int variable


//http://letsdoprogramminginc.blogspot.com/
#include <iostream>
#include<limits>
using namespace std;

int main()
{
    int number;
    cout<<"Enter the the Number \t";
    while(!(cin>>number))
    {
        cin.clear();
        cin.ignore(numeric_limits<streamsize>::max(),'\n');
        cout<<"Invalied input. Try Again only Numbers: ";
    }
    cout<<"\nYour Enter this Number \t"<<number;
    cout<<"\n\n";
}


No comments:

Post a Comment