how do i make the program not crash when the user inputs an alphabet.
the program has to ask to re-enter if the user inputs alphabet. and "pause" when a number is entered.
int main()
{
int number;
cout << "Please type a user input:" << endl;
cin >> number;
//do something with the number... example:
cout << "The value you entered is " << number << endl;
#include <iostream>
int main()
{
int number ;
// ( std::cin >> number ) is 'true' if a number was read from std::cin
while( std::cout << "enter a number: " && !( std::cin >> number ) )
{
std::cout << "you did not enter a number\n" ;
std::cin.clear() ; // clear the error state
std::cin.ignore( 1000, '\n' ) ; // discard the bad input
}
std::cout << "you entered " << number << '\n' ;
}