Quote (smashT @ 10 Oct 2013 05:02)
...
int smallest(int x, int y, int z)
{
111 if (x > y && x > z)
111 return x;
111 else
222 if (y > x && y > z)
222 return y;
222 else
333 if (z > x && z > y)
333 return z;
333 else
333 return 0;
}
I am supposed to rewrite the function without using a nested if... I'm confused by this. I feel like there are no nested ifs, though it might seem that way due to the way he indented. ...
...
if i understand that right you have three levels of ifs here, that is the statements '333' are nested within the '222' and those nested within the '111'
not c++ but i hope you understand anyhow:
...
int returnvalue
returnvalue=0
if (x>y && x>x) returnvalue=x end
if (y>x && y>z) returnvalue=y end
if (z>x && z>y) returnvalue=z end
return returnvalue
..
this is without nested ifs, just ensure that you put it into proper c++ form