need help with calling function twice?

i have to call the aretheysame function twice, once before the roundscore function and once after it. they have to print out different things when called. the first time the call is made it will compare the 3 different test scores and the second time is called it will compare the three rounded scores.

this is my roundscore function:

1
2
3
4
5
6
7
8
9
10
11
int roundscore (int score) {
    int r;
    r = score%10;
    
    if (r >= 5)
        score = score + (10-r);
    else
        score = score - r;
    
    return score;
}


and this is my aretheysame function:

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
void aretheysame (int x, int y, int z) {
    
    if (x == y && y == z) {
        cout<< "all the numbers are the same" << endl;
        return;
    }                    //the first or second if have to print out when this function is called the first time.
    if (x != y && y != z && x != z) {
        cout<< "all the numbers are different" << endl;
        return;
    }                     //one of the if's after this have to print out when the second call is made.
    if (x == y && x < z) {
        cout<< "two numbers are the same and the third is larger"<< endl;
        return ;
    }
    if (y == z && y < x) {
        cout<< "two numbers are the same and the third is larger"<< endl;
        return;
    }
    if (x == z && x < y) {
        cout<< "two numbers are the same and the third is larger"<< endl;
        return;
    }
    if ( x == y && x > z) {
        cout<< "two numbers are the same and the third is smaller"<< endl;
        return;
    }
    if (y == z && y > x) {
        cout<< "two numbers are the same and the third is smaller"<< endl;
        return;
    }
    if (x == z && x > y) {
        cout<< "two numbers are the same and the third is smaller"<< endl;
        return;
    }
    return ;
    }


this is part of the main function where the two functions are used:

1
2
3
4
5
6
7
8
aretheysame (test1, test2, test3);
        if (ans==true) {
            cout<< test1 << " is rounded to " << roundscore(test1) << endl;
            cout<< test2 << " is rounded to "<< roundscore(test2) <<endl;
            cout<< test3 << " is rounded to " << roundscore(test3) << endl;
            
        aretheysame(a=test1,b=test2,c=test3);
        }
When you call roundscore() it does not actually modify the test variables, so when you later call aretheysame() for the second time, it will produce the same results. Your way of calling it is also really strange...did you mean to have those a=/b=/c= in there?
the reason i have it a=test1,... is because i was told to use different parameters and call the function again. and i have to round the scores only if ans=true. how can i fix it so they get modified? thanks
Last edited on
roundscore() returns the rounded answer, so this should do it:
test1 = roundscore(test1);
And calling it again with the test values would (I expect) be different parameters, since you've changed them.
thank you so much!!!!
Topic archived. No new replies allowed.