How can i save on an int or a char depending by the input?

I still didn't figure out how to do it yet. Imagine that you can input everything you want, but when you input 2 the number gets saved in a variable int and if you hit d the character gets stored in a char. How could i do that?
Look up ascii characters.
Below you can see how it works.
In the case of numbers you would have to covert 0-9 from char to int.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
char alpha;

cout << "enter a single value";
cin >> alpha;

	if ((alpha > 64) && (alpha < 123))
	{
		cout << alpha << " is a letter" << endl;
	}
	else
	{
		cout << alpha << " is a non letter" << endl;
	}
	
  return 0;
}


PS. I'm not suggesting this code is the solution, just an example of how it could be done.
Last edited on
Thank you! It's kinda like emu8086 :)
Topic archived. No new replies allowed.