Я делаю html-форму, и когда пользователь отправляет форму, загружается страница aspx для отображения результатов формы.У меня 20 вопросов по 5 радиокнопок в каждом.Каждый переключатель имеет значение от 1 до 5 (категорически не согласен с 1 и строго согласен с 2).Я хочу рассчитать средний балл после отправки формы и отобразить его в текстовом поле.
Я пытался использовать цикл for, чтобы перебрать результаты и сложить их, а затем получить среднее значение.Затем я использовал оператор if / else и попытался соответственно изменить оценку в текстовом поле.
Когда я пытаюсь отобразить оценки, независимо от того, какой выбор я делаю, результат всегда отображается как А. Для обоих.
Вот мой код aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
txtStudentName.Text = Request["txtFirstName"].ToString() + " " + Request["txtLastName"].ToString();
txtID.Text = Request["txtID"].ToString();
txtCourse.Text = Request["dbCourses"].ToString();
double[] scores =
{
double.Parse(Request["q1"]),
double.Parse(Request["q2"]),
double.Parse(Request["q3"]),
double.Parse(Request["q4"]),
double.Parse(Request["q5"]),
double.Parse(Request["q6"]),
double.Parse(Request["q7"]),
double.Parse(Request["q8"]),
double.Parse(Request["q9"]),
double.Parse(Request["q10"]),
double.Parse(Request["q11"]),
double.Parse(Request["q12"]),
double.Parse(Request["q13"]),
double.Parse(Request["q14"]),
double.Parse(Request["q15"]),
double.Parse(Request["q16"]),
double.Parse(Request["q17"]),
double.Parse(Request["q18"]),
double.Parse(Request["q19"]),
double.Parse(Request["q20"])
};
DisplayResults(scores);
CalculateGrades(scores);
}
public void CalculateGrades(double[] scores)
{
double courseScore = 0;
double profScore = 0;
for (int i = 0; i < 12; i++)
{
courseScore += scores[i];
}
double avgCourseScore = courseScore / 12.0;
if (avgCourseScore <= 5)
{
txtCourseGrade.Text = "A";
}
else if (avgCourseScore <= 4)
{
txtCourseGrade.Text = "B";
}
else if (avgCourseScore <= 3)
{
txtCourseGrade.Text = "C";
}
else if (avgCourseScore <= 2)
{
txtCourseGrade.Text = "D";
}
else if (avgCourseScore <= 1)
{
txtCourseGrade.Text = "F";
}
for (int j = 12; j < 20; j++)
{
profScore += scores[j];
}
double avgProfScore = profScore / 8.0;
if (avgProfScore <= 5)
{
txtProfGrade.Text = "A";
}
else if (avgProfScore <= 4)
{
txtProfGrade.Text = "B";
}
else if (avgProfScore <= 3)
{
txtProfGrade.Text = "C";
}
else if (avgProfScore <= 2)
{
txtProfGrade.Text = "D";
}
else if (avgProfScore <= 1)
{
txtProfGrade.Text = "F";
}
}
Вот код для моего aspx
<fieldset>
<legend>Final Grade</legend>
<asp:Label ID="lblCourseGrade" runat="server">Course Grade: </asp:Label>
<asp:TextBox ID="txtCourseGrade" runat="server" BorderStyle="None" ReadOnly="True"></asp:TextBox>
<br /><br />
<asp:Label ID="lblProfGrade" runat="server">Professor Grade: </asp:Label>
<asp:TextBox ID="txtProfGrade" runat="server" BorderStyle="None" ReadOnly="True"></asp:TextBox>
</fieldset>
Вот мой HTML-код
<h3>Please answer these questions to the best of your knowledge:</h3>
<fieldset>
<legend>Course Content (Organization, Clarity of Expectations/Directions, Balance/Appropriateness)</legend>
1. The course (or section) presented skills in a helpful sequence
<br />
<input type="radio" name="q1" value="5" />strongly agree
<input type="radio" name="q1" value="4" />agree
<input type="radio" name="q1" value="3" />neutral
<input type="radio" name="q1" value="2" />disagree
<input type="radio" name="q1" value="1" />strongly disagree
<br />
<br />
2. The course (or section) provided an appropriate balance between instruction and practice
<br />
<input type="radio" name="q2" value="5" />strongly agree
<input type="radio" name="q2" value="4" />agree
<input type="radio" name="q2" value="3" />neutral
<input type="radio" name="q2" value="2" />disagree
<input type="radio" name="q2" value="1" />strongly disagree
<br />
<br />
3. The course (or section) was appropriate for the stated level of the class
<br />
<input type="radio" name="q3" value="5" />strongly agree
<input type="radio" name="q3" value="4" />agree
<input type="radio" name="q3" value="3" />neutral
<input type="radio" name="q3" value="2" />disagree
<input type="radio" name="q3" value="1" />strongly disagree
<br />
<br />
4. The course (or section) was organized in a way that helped me learn
<br />
<input type="radio" name="q4" value="5" />strongly agree
<input type="radio" name="q4" value="4" />agree
<input type="radio" name="q4" value="3" />neutral
<input type="radio" name="q4" value="2" />disagree
<input type="radio" name="q4" value="1" />strongly disagree
<br />
<br />
5. The lab helped to complement the lectures
<br />
<input type="radio" name="q5" value="5" />strongly agree
<input type="radio" name="q5" value="4" />agree
<input type="radio" name="q5" value="3" />neutral
<input type="radio" name="q5" value="2" />disagree
<input type="radio" name="q5" value="1" />strongly disagree
<br />
<br />
6. The course (or section) provided a mixture of explanation and practice
<br />
<input type="radio" name="q6" value="5" />strongly agree
<input type="radio" name="q6" value="4" />agree
<input type="radio" name="q6" value="3" />neutral
<input type="radio" name="q6" value="2" />disagree
<input type="radio" name="q6" value="1" />strongly disagree
<br />
<br />
7. The course (or section) was effectively organized
<br />
<input type="radio" name="q7" value="5" />strongly agree
<input type="radio" name="q7" value="4" />agree
<input type="radio" name="q7" value="3" />neutral
<input type="radio" name="q7" value="2" />disagree
<input type="radio" name="q7" value="1" />strongly disagree
<br />
<br />
8. The course (or section) assignments and lectures usefully complemented each other
<br />
<input type="radio" name="q8" value="5" />strongly agree
<input type="radio" name="q8" value="4" />agree
<input type="radio" name="q8" value="3" />neutral
<input type="radio" name="q8" value="2" />disagree
<input type="radio" name="q8" value="1" />strongly disagree
<br />
<br />
9. The course (or section) instructions (including, manuals, handouts, etc.) were clear
<br />
<input type="radio" name="q9" value="5" />strongly agree
<input type="radio" name="q9" value="4" />agree
<input type="radio" name="q9" value="3" />neutral
<input type="radio" name="q9" value="2" />disagree
<input type="radio" name="q9" value="1" />strongly disagree
<br />
<br />
10. The course (or section) work helped me understand concepts more clearly
<br />
<input type="radio" name="q10" value="5" />strongly agree
<input type="radio" name="q10" value="4" />agree
<input type="radio" name="q10" value="3" />neutral
<input type="radio" name="q10" value="2" />disagree
<input type="radio" name="q10" value="1" />strongly disagree
<br />
<br />
11. Instructions for course (or section) materials (including manuals, handouts, etc.) were clear
<br />
<input type="radio" name="q11" value="5" />strongly agree
<input type="radio" name="q11" value="4" />agree
<input type="radio" name="q11" value="3" />neutral
<input type="radio" name="q11" value="2" />disagree
<input type="radio" name="q11" value="1" />strongly disagree
<br />
<br />
12. The lab complemented my understanding of the lectures
<br />
<input type="radio" name="q12" value="5" />strongly agree
<input type="radio" name="q12" value="4" />agree
<input type="radio" name="q12" value="3" />neutral
<input type="radio" name="q12" value="2" />disagree
<input type="radio" name="q12" value="1" />strongly disagree
</fieldset>
<br />
<br />
<fieldset>
<legend> Instructor Specific Questions</legend>
1. The instructor clearly presented the skills to be learned
<br />
<input type="radio" name="q13" value="5" />strongly agree
<input type="radio" name="q13" value="4" />agree
<input type="radio" name="q13" value="3" />neutral
<input type="radio" name="q13" value="2" />disagree
<input type="radio" name="q13" value="1" />strongly disagree
<br />
<br />
2. The instructor effectively presented concepts and techniques
<br />
<input type="radio" name="q14" value="5" />strongly agree
<input type="radio" name="q14" value="4" />agree
<input type="radio" name="q14" value="3" />neutral
<input type="radio" name="q14" value="2" />disagree
<input type="radio" name="q14" value="1" />strongly disagree
<br />
<br />
3. The instructor presented content in an organized manner
<br />
<input type="radio" name="q15" value="5" />strongly agree
<input type="radio" name="q15" value="4" />agree
<input type="radio" name="q15" value="3" />neutral
<input type="radio" name="q15" value="2" />disagree
<input type="radio" name="q15" value="1" />strongly disagree
<br />
<br />
4. The instructor effectively presented the tools (e.g. materials, skills, and techniques) needed
<br />
<input type="radio" name="q16" value="5" />strongly agree
<input type="radio" name="q16" value="4" />agree
<input type="radio" name="q16" value="3" />neutral
<input type="radio" name="q16" value="2" />disagree
<input type="radio" name="q16" value="1" />strongly disagree
<br />
<br />
5. The instructor explained concepts clearly
<br />
<input type="radio" name="q17" value="5" />strongly agree
<input type="radio" name="q17" value="4" />agree
<input type="radio" name="q17" value="3" />neutral
<input type="radio" name="q17" value="2" />disagree
<input type="radio" name="q17" value="1" />strongly disagree
<br />
<br />
6. The instructor made the elements of good writing clear
<br />
<input type="radio" name="q18" value="5" />strongly agree
<input type="radio" name="q18" value="4" />agree
<input type="radio" name="q18" value="3" />neutral
<input type="radio" name="q18" value="2" />disagree
<input type="radio" name="q18" value="1" />strongly disagree
<br />
<br />
7. The instructor clearly articulated the standards of performance for the course
<br />
<input type="radio" name="q19" value="5" />strongly agree
<input type="radio" name="q19" value="4" />agree
<input type="radio" name="q19" value="3" />neutral
<input type="radio" name="q19" value="2" />disagree
<input type="radio" name="q19" value="1" />strongly disagree
<br />
<br />
8. The instructor provided guidance for understanding course exercises
<br />
<input type="radio" name="q20" value="5" />strongly agree
<input type="radio" name="q20" value="4" />agree
<input type="radio" name="q20" value="3" />neutral
<input type="radio" name="q20" value="2" />disagree
<input type="radio" name="q20" value="1" />strongly disagree
</fieldset>
Я хочу отображать среднюю буквенную оценку на основе значений, представленных переключателями вих соответствующие текстовые поля:
Пример ....
Оценка за курс: A
Оценка профессора: F