While loop in C++

This is simple while loop in c++ i cant figure out where i am wrong but the the loop is running infinitely what should happen is that after “Wrong user prompt” the it should ask again for user input but that’s not happening where am i wrong at in this code ?

#include <iostream>
using namespace std;


int main()
	{
    bool x = true;

		while(x)
			{
				cout<<"input the name"<<endl;
        int b;
				cin>>b;
				
				if( b == 2)
					{
						cout<<"Right User"<<endl;
						x = false;
					}
				else
					{
						cout<<"Wrong input"<<endl;
					}		
				
			}
	}

That’s working properly for me. You may want to use a debugger to figure this out.

you should set the x to false also in else block just like what you did in if block, because without that, it cannot exit the while loop so it will be an indefinite loop