#include<iostream>
#include<conio.h>
//using namespace std; // <--- Best not to use.
int main()
{
int n{}; // <--- Always a good practice to initialize your variables.
char ch{};
ch = _getch();
n = static_cast<int>(ch - 48); // <--- Because 48 is the ASCII code for zero.
if (n == 1)
{
std::cout << "Working";
}
std::cout << "\n\n\n Press any key to continue: ";
_getch();
return 0;
}
I am not sure specifically what you are asking, but I see in your previous post you had a question about a
static_cast
.
The static_cast is used to perform a conversion type conversion between two expressions. In the case of the code snippet this will convert a char to an int. This should not be necessary however an in can be assigned the value of char without using a