"conio.h" is not a standard C++ header file, but if you want to use it I would replace std::cin >> n; with n = _getch();. This gets one character from the keyboard and moves on.
This is a good start for something, but as is it only proves point and does not have much use.
#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;
}
Doing the input as a "char" the character, in this case a number, is stored as the ASCII code 48 decimal or 30 in hex for zero. So subtracting 48 from the ASCII code for 1, which is 49, leaves you with 1 that can be stored as an "int". Using static_cast<int> just makes sure that the end result is stored in "n" as an "int".
This is used quite often to change a "char" to an "int" when you need a number from zero to nine.
Just a suggestion. The code is more readable if it is written as ch - '0' rather than ch - 48
This has at least two advantages:
• it more clearly expresses the programmer intention
• it avoids the need for both original programmer and a later reader to have to memorise the ASCII values
Regarding the cast, it is probably not needed. The compiler automatically does many conversions e.g assigning an int to a variable of type double without it.