Input validation not 100% right

I'm trying to write a menu-driven program for a final project. If the user enters a letter instead of a number, an infinite loop occurs. How do I fix it? The due date was moved up and I have several other projects and I just want to enjoy my summer :'(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
	int number1_6;
	cout << "Enter a number 1-6: ";
	cin >> number1_6;
	while(number1_6 < 1 || number1_6 > 6)
	{
		cout << "Enter only a number 1 - 6 : ";
		cin >>number1_6;
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
bool proceed(false);
while(!proceed) {
    std::cin >> number1_6;
    if(cin.fail()) {
        std::cout << "Enter only a number 1 - 6 : ";
        std::cin.clear();
        std::cin.ignore(numeric_limits<streamsize>::max(), '\n');//include <limits>
    } else if (number1_6 < 1 || number1_6 > 6)) {
        std::cout << "Enter only a number 1 - 6 : ";
    } else 
        proceed = true;
}
Bless you. Thank you. I hope you can imagine how thankful I am. This is for a final project in my intro to programming class and my substandard teacher never even used a bool variable, let alone showed us how to do this, but is holding us responsible for it and has pushed up the due date. I'm so close to an A in the class that it hurts and I still have two other classes to deal with. this has been keeping me from sleeping at night. Now I can finally finish (maybe even on time) and go get a degree at a better school.

thank you!
Topic archived. No new replies allowed.