I tried to make an ASCII converter with an if-statement in C++ , but I get a little confused to declare the input variable . this is the main issue .
I try once with the typeid().name() , then typeid() , finally I go with sizeof() function,
here’s what I’ve tried
#include<iostream>
int main()
{
char character;
std::cout << "Insert Your Characater: ";
std::cin >> character;
if (sizeof(character) == 1)
{
std::cout << "Your Character Refers to : " << int(character);
}
else if (sizeof(character) == 4)
{
std::cout << "nYour Character Refers to :" << char(character);
}
else {
std::cout << "nSomething Went Wrong ... Enter a Number[1,2,3,.....] or an Alphapet[A,a,B,b,C,c,.....] or a Character[(,),-,_,...]";
}
}
Any suggestion to get this done?
New contributor
Mahmoud Tarek Mahmoud is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11