m having problem with my code i need my character to move down the stairs , however i get an error message saying char movement is being used without being initialized
int main()
{
CursorController crs;
ColourController cl;
int Number;// the number of stairs
int Amount = 1; // this is the amount of x it will add to the line
string A;// this is the variable for the character
char movement;// this is the variable to move the character
double xval ,yval;
xval= 20;// the set x postion coordinates
yval = 20;//the set x postion coordinates
cout << "Enter in how many 'stairs' you want" << endl;
cin >> Number;
cout << " now enter a special character to move up and down the starirs \n";
cin >> A;
for(int i = 0; i < Number; i++)
{
for(int j = 0; j < Amount; j++)
{
cout << "*";//the charater for the stair
}
cout << endl;
Amount +=1; //Adds 1 'X' after every new line
}
while( movement =='i')
{
yval=yval-0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movement;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys
}
while( movement == 'k')
{
yval=yval+0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movement;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys
}
while( movement == 'j')
{
xval=xval-0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movement;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys
}
while( movement == 'l')
{
xval=xval+0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movement;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys
}
while(movement!='x')
qin>> movement;
cout<< " you have terminated the program \n";
Do you understand that every variable has a value?
int x = 7;
What is the value of x here? Can you tell me that?
That answer is 7.
char b = 'a';
What is the value of b here? The answer is 'a'.
char movement;
What is the value of movement here? Can you tell me? No you can't, because it could be anything. It has not been initialised. The variable movement has been created, but it has not been set to a value.
In your code, you do this: while( movement =='i')before you set a value in movement. How can you try to compare it? It could be anything. It could be 'z'. It could be '4'. It could be 'i'. It could. Be. Anything.