Hey! I'm currently working on a project but I just can't seem to get my functions to work properly, the first works fine, but the second doesn't do anything. If anyone could help point me in the right direction, it'd be appreciated.
char getPosition (float a, float b)
{
char z;
if (a > 0 && b > 0)
z='1';
elseif (a > 0 && b < 0)
z='2';
elseif (a < 0 && b < 0)
z='3';
elseif (a < 0 && b > 0)
z='4';
elseif (a==0 && b==0)
z='o';
elseif (a==0 && (b > 0 || b < 0))
z='x';
elseif ((a > 0 || a < 0) && b==0)
z='y';
return z;
}
void printPosition (float a, float b, char z)
{
getPosition(a,b);
switch (z)
{
case'1': cout << "==> (" << a << ", " << b << ") is above the x axis\n" << "==> it is at first quadrant.\n" << endl;
break;
case'2': cout << "==> (" << a << ", " << b << ") is above the x axis\n" << "==> it is at second quadrant.\n" << endl;
break;
case'3': cout << "==> (" << a << ", " << b << ") is below the x axis\n" << "==> it is at third quadrant.\n" << endl;
break;
case'4': cout << "==> (" << a << ", " << b << ") is below the x axis\n" << "==> it is at third quadrant.\n" << endl;
break;
case'o': cout << "==> (" << a << ", " << b << ") is at origin.\n" << endl;
break;
case'x': cout << "==> (" << a << ", " << b << ") is along x axis.\n" << endl;
break;
case'y': cout << "==> (" << a << ", " << b << ") is along y axis.\n" << endl;
break;
}
Your first function is returning a value, but you aren't actually putting it anywhere in your second function, so it is being thrown away. Note that you are passing z in as a parameter, which doesn't make any sense since you should be getting it from getPosition.