From PHP to ASP.NET

Taking User input to find average of three numbers in a ASP.NET web page

Let me show it first, so this is taking User inputs to find average of three numbers in a ASP.NET web page.
I’d like to post the PHP code also with the same configuration so that you can understand the diference between these two great dynamc web language.
Now the code part, the code behind page is like this:

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
decimal num1 = decimal.Parse(TextBox1.Text);
decimal num2 = decimal.Parse(TextBox2.Text);
decimal num3 = decimal.Parse(TextBox3.Text);

TextBox3.Text = “”;
TextBox2.Text = “”;
TextBox1.Text = “”;

decimal[] Score = { num1, num2, num3 };
decimal Total = 0;
foreach (int i in Score)
{
Total += i;
}
if (Score.Length > 0)
{
Label1.Text = “The avarage was ” + Total / Score.Length;
}
Label1.Text += ”
And the total was ” + Total.ToString();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s