private void Perm(SGrades Grades, Double gpaNeeded) { //number of missing classes k = Grades.UnfilledCount; //array of length missing classes buf = new int[k]; //instantiate list for the lowest grade possble to pass List <string> lowestGrade = new List <string>(); if (k > 0) { //return list of lowestgrade List <string> lowest = rec(0, 0, Grades, gpaNeeded, lowestGrade); //check for if the student can pass the course if (listOut.Items.Count <= 0) { listOut.Items.Add("No grades will make you pass, talk to your counselor about retaking courses"); } listOut.Items.Add(""); listOut.Items.Add("The Lowest grades you will need to pass in each course are:"); //output the lowest grade possible in each course foreach (string a in lowest) { listOut.Items.Add(a); } if (ListItems.Count > 0) { listOut.Items.Add(string.Empty); foreach (string item in ListItems) { listOut.Items.Add(item); } } } }
protected void Calculate(object sender, EventArgs e) { if (Page.IsValid) { List <TextBox> gradeInputs = Session["gradeTextboxes"] as List <TextBox>; SGrades Grades = new SGrades { FilledCount = 0, FilledHours = 0, TotalCount = 0, UnfilledCount = 0, QualityPoints = 0, TotalHours = 0, MissingHours = 0, GPA = 0 }; int visibleRows = 0; //for loop o count every visible row for (int i = 1; i < mainTable.Rows.Count; i++) { if (mainTable.Rows[i].Visible == true) { visibleRows++; } } /// for (int k = 1; k < mainTable.Rows.Count; k++) { if (mainTable.Rows[k].Visible == false) { continue; } List <TextBox> TextBoxes = new List <TextBox>(); for (int i = 0; i < mainTable.Rows[k].Cells.Count; i++) { foreach (TextBox TxtBox in mainTable.Rows[k].Cells[i].Controls.OfType <TextBox>()) { TextBoxes.Add(TxtBox); } } if (TextBoxes.Count() > 2) { if (TextBoxes[0].Text.Length <= 0) { lblGPAOut.Text = "Client side manipulation detected"; return; } if (!int.TryParse(TextBoxes[1].Text, out int Hours)) { lblGPAOut.Text = "Client side manipulation detected"; return; } else { Grades.TotalHours += Hours; } if (TextBoxes[2].Text.Length > 0) { if (!int.TryParse(TextBoxes[2].Text, out int Grade)) { lblGPAOut.Text = "Client side manipulation detected"; return; } else if (GradeValues.Contains(Grade = GetGrade(Grade))) { Grades.QualityPoints += (Grade * Hours); Grades.FilledHours += Hours; Grades.FilledCount++; } else if (Hours == 5) { ListItems.Add($"{TextBoxes[0].Text} has a grade lower than 50. You cannot have failing grades."); ListItems.Add("Considering it never taken for calulations"); ListItems.Add(string.Empty); Unfilled.Add(new ClassHolder { ClassName = TextBoxes[0].Text, CreditScore = Hours }); Grades.UnfilledCount++; Grades.MissingHours += Hours; } } else { Unfilled.Add(new ClassHolder { ClassName = TextBoxes[0].Text, CreditScore = Hours }); Grades.UnfilledCount++; Grades.MissingHours += Hours; } Grades.TotalCount++; } } //calculate GPA with method call Grades.GPA = (double)Grades.QualityPoints / Grades.FilledHours; lblQPOut.Text = Grades.QualityPoints.ToString(); lblHoursOut.Text = Grades.FilledHours.ToString(); lblQP.Text = Grades.QualityPoints.ToString(); lblHours.Text = Grades.FilledHours.ToString(); if (Grades.UnfilledCount <= 0) { lblGPAOut.Text = Grades.GPA.ToString("0.00"); return; } //calculate the student's missing quality points double QPneeded = ((Grades.TotalHours * 2) - Grades.QualityPoints); //output to label Perm(Grades, QPneeded); } else { } }