Input validation of lowercase letters using only while loop.

I am new to c++ and just trying to make something simple to work.
I am trying to do something where the user can only input lowercase letters(a-z)and they would get prompted with a congratulatory message saying that their input is valid and the loop would stop. But if they input anything other than lowercase letters(i.e., uppercase letters, or symbols or characters), they will get an error message and will be prompted to input another letter. All this using a while loop. thank you! Here is my code:


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
char ch;

cout << "Enter a character:";
cin >> ch;

while(ch >= 'A' && ch <= 'Z') {
cout << "Not a valid entry. \n";
cout << "The character " << ch << " is invalid. " << "Try again. \n";
cout << "Enter another character: \n";
cin >> ch;
}
cout << "Congratulations valid entry! \n";
cout << "The character you entered is: " << ch << endl;
return 0;
}
Topic archived. No new replies allowed.