Monday, September 26, 2016

Area of Square Solver in C#

Here is a simple program that I wrote using C# as my programming language that will ask the user to give the side length of the square and then our program will compute the area of the square. The code is very simple and easy to understand.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int side = 0, area=0;

            if (!int.TryParse(textBox1.Text, out side))
            {
                MessageBox.Show("I need just a number in the textbox.");
                textBox1.Text = "";
                textBox1.Focus();
            }

            else
            {
                side = Convert.ToInt32(textBox1.Text);

                area = (side * side);
                label3.Text = "The Area of the Square is " + area + ".";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label3.Text = "";
            textBox1.Focus();
        }
    }
}







No comments:

Post a Comment