Help Needed - Calculating Average Grade

1. Junior Member
Join Date
Dec 1969
Posts
4

## Help Needed - Calculating Average Grade

Hey my task is to create a program that calculates the average grade for a student. I have created the interface and it looks like this:<BR><BR>http://mr-29717.mr.valuehost.co.uk/averager.jpg<BR><BR>The 3 grades are entered into Assignment 1, Assignment 2 and Exam, then the user clicks the Calculate Overall Grade button to automatically get the overall grade.<BR><BR>Here is some of the code, i dunno what else to do. How do i link this to the textboxs? Help would be appreciated.<BR><BR>public static string GetGrade(int val)<BR>{<BR>if(val &#062;= 23 & val &#060;= 24)<BR>return "A+";<BR>else if(val &#062;= 20 & val &#060;= 22)<BR>return "A";<BR>else if(val &#062;= 17.5 & val &#060;= 18)<BR>return "A-";<BR>else if(val &#062;= 16.5 & val &#060;= 17)<BR>return "B+";<BR>else if(val &#062;= 15.5 & val &#060;= 16)<BR>return "B";<BR>else if(val &#062;= 14.5 & val &#060;= 15)<BR>return "B-";<BR>else if(val &#062;= 13.5 & val &#060;= 14)<BR>return "C+";<BR>else if(val &#062;= 12.75 & val &#060;= 13)<BR>return "C";<BR>else if(val &#062;= 12.25 & val &#060;= 12.5)<BR>return "C-";<BR>else if(val &#062;= 11.5 & val &#060;= 12)<BR>return "D+";<BR>else if(val &#062;= 10.5 & val &#060;= 11)<BR>return "D";<BR>else if(val &#062;= 9.5 & val &#060;= 10)<BR>return "D-";<BR>else if(val &#062;= 8 & val &#060;= 9)<BR>return "Mp";<BR>else if(val &#062;= 6 & val &#060;= 7)<BR>return "Mp-";<BR>else if(val &#062;= 3.5 & val &#060;= 5)<BR>return "F";<BR>else if(val &#062;= 1 & val &#060;= 2)<BR>return "F-";<BR>else if(val &#062;= 0 & val &#060;= 1)<BR>return "Z";<BR><BR>}

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Code makes no sense!

What happens if the val argument is 25.0?<BR><BR>Or if it is 14.25? Or 7.5? Or 3.0? <BR><BR>Or any of many other possible values.<BR><BR>Of course, *NONE* of those fractional values are AT ALL possible, since the argument to the function is declared as int. What&#039;s the point of even CHECKING for fractions if you only have an integer argument???<BR><BR><BR>Your code shouldn&#039;t even have compiled, because not all values of val will return something from the function!<BR><BR>You complicate your life horribly by using RANGES like that.<BR><BR>THINK about how return works: It *ENDS* the function *IMMEDIATELY* and returns the value specified. So if you know the score is NOT &#062;= 23 (because it didn&#039;t return from the first if test, then why do you need to check the upper limit????<BR><BR>Further, why do you need the else keyword then???<BR><BR>public static string GetGrade(double val)<BR>{<BR> if(val &#062;= 23) return "A+";<BR> if(val &#062;= 20) return "A";<BR> if(val &#062;= 17.5) return "A-";<BR> if(val &#062;= 16.5) return "B+";<BR> if(val &#062;= 15.5) return "B";<BR> if(val &#062;= 14.5) return "B-";<BR> if(val &#062;= 13.5) return "C+";<BR> if(val &#062;= 12.75) return "C";<BR> if(val &#062;= 12.25) return "C-";<BR> if(val &#062;= 11.5) return "D+";<BR> if(val &#062;= 10.5) return "D";<BR> if(val &#062;= 9.5) return "D-";<BR> if(val &#062;= 8) return "Mp";<BR> if(val &#062;= 6) return "Mp-";<BR> if(val &#062;= 3.5) return "F";<BR> if(val &#062;= 1 ) return "F-";<BR> return "Z";<BR>}<BR><BR>*****************<BR><BR>&#06 2; How do i link this to the textboxs?<BR><BR>What textboxes? How do you CALL the function in the first place?<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•