You are using a version without Ads of this website. Please, consider donating:

### 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:

 ``1234567891011`` ``````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:

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````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:

 ``12345678`` ``````aretheysame (test1, test2, test3); if (ans==true) { cout<< test1 << " is rounded to " << roundscore(test1) << endl; cout<< test2 << " is rounded to "<< roundscore(test2) <
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.