How to do calculate a grade?

Hi

I really had no clue where to put this question so I put it here since I guess it has to do with programming.

Say I these marks

A

Mark = 80

OutOff = 100

Weight(how much is the assignment worth to your overall grade) = 50 (in this case it is worth half of the possible 100%)

B

Mark = 50

OutOff = 50

Weight = 30

So 80% of the possible 100% has been given out in this given course. This means what ever else is given in this course cannot total more then 20%

so my OverallMark right now would be

A = (80/100) * 50 = 40

B = (50/50) * 30 = 30

C = (A + B) / 100 = 70

OverAllMakrk = 70%

Current Mark = 70/80 = 87.5%

Now my problem is when I add it differently I get different totals. I don't know which way is now right and how I can get them both to have the same mark.

What I tried

80 + 50 = 130

100 + 50 = 150

130/150 * (50 + 30) = 69.33333 OverallGrade .67% 0ff(but this does not include that unknown 20%).

So I am not sure how to factor that in. Yet I don't know if it is my example or what because it is pretty close but still almost 1% difference is major since it can mean the difference between a "A" and B" or a "pass" or "fail"

Then I tried current Mark

69.3333 / 80 = 86.67% difference of .83%

So is there away I can close this gap? Is all this caused just by rounding?

Since it will make my life alot easier when programing if I can just total everything up rather then having to do it one by one.