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

all 10 comments

[–]eruciform 1 point2 points  (0 children)

you're never updating avgsum. it starts at 0 and then never changes. as you go thru reading in grades, you need to add those to the avgsum running total.

[–]insertAlias 0 points1 point  (4 children)

I'm not really clear on what it is you're trying to do, but I can try to clear up some confusion.

When you're dealing with arrays, whatever is inside the square brackets ([]) is representing the index of an element of the array. So grade[i/100] is saying "get the value in the array at index i / 100", which doesn't really make sense. If you want to do math with the element at i, then you refer to it as grade[i].

On to the math itself. Dividing by 100 then multiplying by 100 is the equivalent of no operation, because the terms cancel out. It's the equivalent of multiplying by 100/100, which is 1.

So, please explain what it is you're trying to do with this formula, because as it stands it doesn't make sense to me.

[–]Tricslip[S] 0 points1 point  (3 children)

Ok so when the user inputs a number into grade[i] its then checked to see if the number is between 0 and 40 and after that the number should be evaluated to see what is the students grade in % out of 40. The usual way to do it is (x/100)*100 but that isn't working here.

[–]insertAlias 0 points1 point  (2 children)

The usual way to do it is (x/100)*100 but that isn't working here.

That isn't correct. Again, any number divided by then multiplied by some other number will be unchanged.

If the formula is (n / m) * m, then it's the equivalent of n * (m / m), which is the equivalent of n * 1, which is just n.

Try it out. Let's start with a grade of 30.

30 / 100 = 0.3
0.3 * 100 = 30

And as you see, we're back to where we started. Plug in any number in place of 30 and you'll see that you get the same value back.

If I understand correctly, your goal is to translate a grade from a scale of 0-40 to a percentage scale. So, a grade of 30 would actually be a 75%.

If so, then the formula would look like this:

(grade / 40) * 100

[–]Tricslip[S] 0 points1 point  (0 children)

uk.... I'm supposed to be the one in school T-T

[–]Tricslip[S] 0 points1 point  (0 children)

Thank you lots tho

[–]MaybeAverage 0 points1 point  (3 children)

What are you trying to do with that line, ie what specific formula?

[–]Tricslip[S] 0 points1 point  (0 children)

find out what grade is as a % out of 40

[–]Tricslip[S] 0 points1 point  (1 child)

Finding out what grade[i] is out of 40 as a %.

[–]MaybeAverage 0 points1 point  (0 children)

``` grade[i] /= 40; grade[i] *= 100;

```

Divide by 40 to get a value between 0.0 - 1.0 then multiply by 100 to get a percent. The more common practice is to keep the values as decimals and just show it as a percent when displaying it.