Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11836
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Can't see to pass the lowestScore variable to the Main function. |
| Date | 2011-11-26 00:58 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <9jartsFedlU1@mid.uni-berlin.de> (permalink) |
| References | <4b774690-2897-4cbf-9c09-af4492e9bd78@q9g2000yqe.googlegroups.com> |
Russell Stanford <russell.stanford@g.austincc.edu> wrote:
> Can anyone help me figure out why the lowestScore variable is not
> passed to the Main function. I can get it to return in one function
> but not two functions. Any suggestions, I am sure this is a no
> brainer, but I have been fiddling with this for too long now.
<code snipped>
Perhaps you should first figure out why your program doesn't
compile. The most revealing one is a complaint of the compiler
about 'lowestScore' being not declared in the calcAverage()
function. It's defined in main() (not Main()) and thus it exists
only in that function (main()) and nowhere else.
Out of curiosity, why do you pass the first five arguments to
calcAverage() as ints but the last one as a reference?
Are you aware of the difference between normal and integer di-
vision? If you're not the line
avg = ((s1 + s2 + s3 + s4 + s5 + s6) - lowestScore) / 5;
from calcAverage() will be the next one that will get you into
trouble: you add (and subtract) a bunch of integers, resulting
in another integer, which you then divide by an integer (and
assign the resuly to a floating point variable). Do you know
that the result of e.g.
17 / 5
will be 3 even if you assign it to a floating point variable?
You might expect to get 3.4 but that's not what you will get
because dividing an integer by an integer will always result
in another integer (the one you will get when you through away
everything after the decimal point). If you want a floating point
result you need at least the divisor or the dividend to be a floa-
ting point value, i.e.
17.0 / 5 or 17 / 5. (or 17. / 5.0)
Assigning the result of an integer division" to a floating
point variable won't change anything about the trunation to
an integer that already happens when the division of two
integers is done.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can't see to pass the lowestScore variable to the Main function. Russell Stanford <russell.stanford@g.austincc.edu> - 2011-11-25 16:20 -0800 Re: Can't see to pass the lowestScore variable to the Main function. jt@toerring.de (Jens Thoms Toerring) - 2011-11-26 00:58 +0000 Re: Can't see to pass the lowestScore variable to the Main function. Richard Damon <news.x.richarddamon@xoxy.net> - 2011-11-25 20:04 -0500 Re: Can't see to pass the lowestScore variable to the Main function. red floyd <no.spam.here@its.invalid> - 2011-11-25 17:12 -0800
csiph-web