I am doing a c++ assignment and just need a little help. I would just like to know how to get the ASCII code number after inputing an ASCII character. The user of this program should be able to input an uppercase letter and recieve the ASCII code value and its corresponding lower case letter with ASCII code value.

Thanks:icon_smile:

just output the character as an integer, you might have to typecast it depending on what functions you use to display it.

> I would just like to know how to get the ASCII code number after inputing an ASCII character.
a. change the locale of std::cin from the default locale to one using an ASCII char set.
b. read the char entered by the user
c. convert it to an int to get the ascii code point.
d. use the tolower member of the ctype facet of the locale imbued by std::cin to get the lower case character
or check for the code point to be in the range for upper case chars; add 32 to get the lower case char (works for ascii)

char c;
cin >> c;
// verify c is an upper case letter
c = c + 'a'-'A';

>a. change the locale of std::cin from the default locale to one using an ASCII char set.
>b. read the char entered by the user
>c. convert it to an int to get the ascii code point.
>d. use the tolower member of the ctype facet of the locale imbued by std::cin to get the lower case character
Somehow I get the impression that the assignment isn't expecting an internationalized solution. :D

>// verify c is an upper case letter
>c = c + 'a'-'A';
For future reference, while this works with ASCII, UTF-8, and UTF-16 (the encodings you're most likely to be dealing with), it's not strictly portable across all character sets. So keep in mind that while this may be how your teacher wants you to complete the assignment, isupper/islower and toupper/tolower provide a more robust solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.