mardi 10 février 2015

If statement in cases not working/being reached

I currently have a program that proceeds to get input, which initially sets the value of b to TRUE (i.e b = 1). Then the switch statement kicks in, setting the value of c to TRUE (i.e c = 1). The next input from the user sets the value of b to FALSE, but the first if statement is never reached for some reason, as the line "mvprintw(22,24,"It has reached it");", is never printed on my screen, despite the fact that the value of b is false(b = 1), and the value of c now is true (c=1).


I've tried using nested if's instead of cases but that proceeds to complicate things further, and quite frankly doesn't work. Any input on this matter would be much appreciated!



int moveC(int y, int x, int b, int i)
{ //first input from user, b is True, so first case occurs
//second input from user, b is false, so second case occurs, however, the if first if statement is never reached, but the second one is
int c = FALSE;

switch(b)
{
case TRUE:
c = TRUE; //this part is first reached from initall user input
refresh();
mvprintw(26,26,"value of c is... %d",c);
break;

case FALSE:
if(c == 1) //this part is never reached, even though the second user input is (b = 0 i.e false, and c = 1, i.e true)
{
mvprintw(22,24,"It has reached it");
mvprintw(y,x+7,"^");
refresh();
break;
}

else if(c == 0) //this if statement is always used even if c is not zero
{
mvprintw(y,x,"^");
refresh();
break;
}

Aucun commentaire:

Enregistrer un commentaire