In c++ how would I create a code where If I press 'A' in the input, it then output '1' and for 'B' 2 and so on | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In c++ how would I create a code where If I press 'A' in the input, it then output '1' and for 'B' 2 and so on

7th Nov 2022, 8:21 AM
Sarel
Sarel - avatar
2 Answers
0
You can literally hardcoded it using switch() statement, Or Just dirrectly convert character into integer minus 64 (A is 65 in Acii) like: int main() { char c; cin >> c; int num = c; cout << num - 64; return 0; }
7th Nov 2022, 1:32 PM
Muhamad Iqbal Chaniago
Muhamad Iqbal Chaniago - avatar
0
Thx 🌱
7th Nov 2022, 1:50 PM
Sarel
Sarel - avatar