Reputation: 6490
My problem is that when I try to calculate the grade with assignments where there is less than 25/25 the grade goes to 75%. Disregarding any other points in my section.
So if every assignment has 100% on I get:
Grade A
Percentage 105%
Labs 250 / 250
But when 1 point out of labs is missing:
Grade C
Percentage 75%
Labs 249 / 250
Why would that be? I'm bit confused with this.
This is how I gather input from my text fields. Every text field is calling this: AutoPostBack="True" OnTextChanged="textbox_TextChanged"
.
foreach (Control control in Page.Controls)
{
foreach (Control textbox in control.Controls)
{
if (textbox is TextBox)
{
TextBox tb = textbox as TextBox;
char type = tb.ID.ToCharArray()[0];
if (!string.IsNullOrWhiteSpace(tb.Text))
{
if (type == 'l')
{
int outtt;
string inn = tb.Text;
Int32.TryParse(inn, out outtt);
labs += outtt;
labPoints += 25;
}
else if (type == 'q')
{
...
}
...
}
}
}
}
This is how I calculate the percentage:
percent = (((labs / labPoints) * 0.3) + // labs
((quizzes / quizPoints) * 0.1) + // quizzes
((exams / examPoints) * 0.3) + // exams
((project / projectPoints) * 0.2) + // project
((extra / extraPoints) * 0.05) + // extra credit
((part / partPoints) * 0.10)) * 100;// participation
Upvotes: 0
Views: 152
Reputation: 10460
You are using integer division, which will always result in an integer. For a quick and dirty fix you should cast your variables to some floating point variables when you divide them.
e.g.:
(double)labs / (double)labPoints
(If any of the arguments is a double then the result will be a double.)
Upvotes: 4