0

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;
}
2
  • Hi, please refer to this question for clarification - stackoverflow.com/questions/46736705/… Commented Jun 20, 2018 at 3:53
  • How do you expect the program to read letters into an integer variable? Commented Jun 20, 2018 at 4:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.