Yes, but that will not work in your case.
if
block itself is a scope, and you define a scope and the variables are only accessible inside the scope, not outside, and not at the boundary either.
So, I think something you would want to do would be,
cin >> y;
if (y > 10)
{
double x = y * 15;
This would work, and will test if the value of y is greater. Why I think this would be the right approach? Because, you just took input in the
y
variable, and you would now need to test if the input from user was more than 10.
Otherwise, you can do this,
cin >> y;
double x = 0; if (x > 10)
{
x = y * 15;
But notice, that now your
if
block would never execute, because it won't be more than 10 and thus if block would never executed.
Scope - cppreference.com[
^]