restriction

am trying to make a menu that have a restriction using alphabet.
and want to know how to implement a condition containing (ascii).

how do i make a condition that only accept certain letters to my entered by the
user??

[code]
#include<iostream>
#include <stdlib.h>

using namespace std;
int main()
{

char ascii;
cout<<"enter letter ";
cin>>ascii;

if ((int)ascii >97 && (int)ascii <101)
{
cout<<"echoing...please enter a valid choice\n";

}

}
your code seems to working fine whats wrong with it?
the simple way
1
2
3
4
5
6
    if (isalpha(ascii)){
        cout << "is a letter";
    }
    else{
        cout << "is not a letter";
    }


but your only checking ascii numbers 97 through 101, it would be 97 through 122 for lower case
http://www.asciitable.com/
oh yeah i just want to restrict the users choice from (a-e ) only..
you want the >= and <= comparisons respectively. You are only searching 98-100
 
if (ascii >= 'a' && ascii <= 'e')

is a lot clearer that checking the binary values from the ASCII table.

@abstraction : what if 'b' is entered? will the condition fail? coz i want leters (a,b,c,d,and e) to be the valid input otherwise says "invalid input pease try again";

thanks
what if 'b' is entered? will the condition fail?

@dharmendra1281
did you even put his suggestion in your code and test it for yourself?
@metulburr
sorry boss
ok i will try .. very sorry for asking such stupid question..
Topic archived. No new replies allowed.