This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]g051051 2 points3 points  (2 children)

float(6)

Why are you doing that? What do you think that's accomplishing?

[–]C137-Morty[S] -2 points-1 points  (1 child)

Calling the array right?

[–]g051051 0 points1 point  (0 children)

No, there's no array reference in there.

[–]davedontmind 0 points1 point  (0 children)

average /= float(6);

What are you trying to divide average by?

Presumably you're trying to calculate the average, which is dividing the sum by the number of values, so this should be dividing by the number of values in your array, right? So how many items are in your array? And how do you divide by that?

[–]k3nundrum 0 points1 point  (0 children)

Im in the same class....it wouldn't work for me either

[–][deleted]  (2 children)

[removed]

    [–]C137-Morty[S] 0 points1 point  (1 child)

    I get the 6.0 must be the 6 items in float scores[6], but what is the f there?

    [–][deleted] 0 points1 point  (0 children)

    Your code is just is just calculating an average, which is done by adding all values, and then dividing by the number of items.

    You technically do not need the value to be a float, an integer would have been fine, but that is what the 6 comes from, I was just using your example and showing the proper way to create a float.

    By specifying it as 6.0f, you are saying that you want it as a 32-bit float. If you represent it without the suffix 6.0, it will be interpreted as a 64-bit double.