Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to calculate a weighted average. Each assignment weighs 10%, midterm 30%, and final 40% for the following:

XML
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl3.Text="Grade on Assignment 1: " & txt1.Text
lbl4.Text="Grade on Assignment 2: " & txt2.Text
lbl5.Text="Grade on Assignment 3: " & txt3.Text
lbl6.Text="Grade on Midterm: " & txt4.Text
lbl7.Text="Grade on Final: " & txt5.Text
lbl8.Text="Weighted Average: " & txt7.Text
txt1.Text=""
End Sub
</script>

<html>
<body><form runat="server">
Enter your grades for the following assessments:
<p>Assignment 1: <asp:TextBox id="txt1" runat="server" /></p>
<p>Assignment 2: <asp:TextBox id="txt2" runat="server" /></p>
<p>Assignment 3: <asp:TextBox id="txt3" runat="server" /></p>
<p>Midterm: <asp:TextBox id="txt4" runat="server" /></p>
<p>Final: <asp:TextBox id="txt5" runat="server" /></p>
<asp:Button OnClick="submit" Text="Submit" runat="server" />

<p><asp:Label id="lbl1" runat="server" /></p>
<p><asp:Label id="lbl2" runat="server" /></p>
<p><asp:Label id="lbl3" runat="server" /></p>
<p><asp:Label id="lbl4" runat="server" /></p>
<p><asp:Label id="lbl5" runat="server" /></p>
</form></body>
</html>


I know how to do arithmetic in asp using <% Response.Write(result) %> as follows:

<% Dim A,B,C, result
A = request.form("txt1")
B = request.form("txt2")
C = request.form("txt3")
D = request.form("txt4")
E = request.form("txt5")
'Use CInt() to convert A,B, C to integer type
result = CInt(A)*.10+CInt(B)*.10+CInt(C)*.10+CInt(D)*.30+CInt(E)*.40
'Use CDbl() to convert result to double type
%>
<p>Your calculated grade is  <% Response.Write (result) %></P>


I want to perform the same exact operation, but in asp.net. How do I do this?
Posted
Updated 13-Apr-13 17:14pm
v2

1 solution

Ever heard of separation of concerns? Calculations are calculations, they do not depends on what is the application, ASP.NET or not. The question makes no sense at all.

—SA
 
Share this answer
 
Comments
Imperfection 13-Apr-13 23:37pm    
I've done arithmetic in asp, where you take the values from textboxes and form a code so that when numbers are entered, it will calculate it and give a weighted average.
This is for a school project. I cannot figure out how to do in asp.net as I did in asp.
Sergey Alexandrovich Kryukov 14-Apr-13 1:17am    
This sounds exactly like "I have no idea how to do programming, please help". You see, this forum suggests some prerequisites. The questions should be minimally qualified. "I cannot figure out" cannot be considered as a productive question. Certain things cannot be learned from forums; you rather need to go back to your school where they can help you with elementary basics...
—SA
Imperfection 14-Apr-13 1:55am    
Yes, I know, you're right. And honestly, that is exactly what it is. I have no idea how to do programming. I signed up for IT Web Design as an elective because my adviser told me I can take any upper-level electives. This is a class I am not even qualified for and has nothing to do with my major; thus, I am stuck, and the drop deadline has already passed for the semester. I did not drop it earlier because I was doing find and somehow maintaining an A in the class. I just got stuck on this one part, for this one assignment, and figured I could use the internet for some help.
I understand I've came to the wrong place. Thank you for your time and patience.
Sergey Alexandrovich Kryukov 14-Apr-13 1:57am    
Thank you for understanding. I just need to slow down and pay more effort toward the basics...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900