Function help

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

  char getPosition (float a, float b)
{
    char z;
    
    if (a > 0 && b > 0)
        z='1';
    else if (a > 0 && b < 0)
        z='2';
    else if (a < 0 && b < 0)
        z='3';
    else if (a < 0 && b > 0)
        z='4';
    else if (a==0 && b==0)
        z='o';
    else if (a==0 && (b > 0 || b < 0))
        z='x';
    else if ((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.
I think you don't need z as parameter, declare z as local var, and assign value that returned from getposition() to z like
char z=getposition(a,b)
Sorry, not quite sure how to assign the value.
You may want to read his entire post.
Apologies, just tried it out again and it worked. Thanks for your assistance firedraco and LendraDwi.
Topic archived. No new replies allowed.