I'm learning c++ on my own and don't have a teacher.
I've created a program that asks the user to enter their password over and over again until they enter the right password. It works, unless the user enters letters instead of integers. It just creates an infinite loop.
Could someone take a look at it and tell me what's wrong with it? Thank you!
#include <iostream>
using namespace std;
int main()
{
int password= 123456;
cout<< "Enter your password: "<< flush;
int input;
cin>> input;
while(input!=password) {
cout<< "Access denied."<< endl;
cout<< "Enter your password: "<< flush;
cin>> input;
}
cout<< "Access granted."<< endl;
return 0;
}