Click to See Complete Forum and Search --> : question about user-defined functions


gurlygurlz
February 22nd, 2003, 06:34 PM
As an assignment, I have to write a program that records stats to a basketball game for a team and their opponent . I MUST include a function called point_shoot to find the shooting percent (2 pointers made/ 2 pointers attempted) for 2 pointers, 3 pointers, free throws, and overall. The function point_shoot must be called multiple times in the program. My output must have this (example)

Team---------2 pointers----------3 pointers--------Overall---------Freethrows
AHS---------9/11=81.81%----------2/3 =66.67%--------etc.
PHS---------6/15=40.0%----------3/6= 50.0%

I am confused as to how I can call the point_shoot function multiple times and have it store each set of input to be able to output the percentages for AHS 2 pointers, 3 pointers etc. and PHS 2 pointers, 3 pointers, etc.

I am a beginner at C++ and just learned user-defined functions.

Thanks

PaulWendt
February 22nd, 2003, 07:10 PM
You already posted this and I replied to the other post.
--Paul

gurlygurlz
February 22nd, 2003, 08:29 PM
i know but i do not understand...

how is it going to keep track of 2pointers, 3 pointers etc. for each team so that i can output it all at the end. wouldnt it write over the first input when i input the second made and attempted?

PaulWendt
February 22nd, 2003, 08:39 PM
Well, does it definitely have to store the percentages? You could
print out the percentages as you know them and get the same
effect.

gurlygurlz
February 22nd, 2003, 09:58 PM
No, I have to have formatted output at the end

Team-----2-pointers------3-pointers------Overall-----FreeThrows
CHS---------#/#=%--------#/#=%---------#/#=%------#/#=%
PHS -------SAME AS ABOVE------

PaulWendt
February 22nd, 2003, 10:04 PM
Well there you go :)

Just modify the routine I gave you earlier so that you pass in the
high school name too. Then alter the cout statements so that
you are printing in the style you need.

The main thing to keep in mind is that you don't want global
variables all over the place; the method you were using was
prohibiting the easy reuse of functions.

--Paul