Noob need help again!

can somebody please eloborate me this code please?
thank you so much in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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
static_cast
Topic archived. No new replies allowed.