Menu



Manage

Study_C# > 4-minicalc/Form1.cs Lines 97 | 2.9 KB
다운로드

                        using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

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

        private void add_Click(object sender, EventArgs e)
        {
            float num1, num2, re;
            if (float.TryParse(tbxnum1.Text, out num1))
            {
                if (float.TryParse(tbxnum2.Text, out num2))
                {
                    re = num1 + num2;
                    if (re % 1 == 0) {
                        re = (int)Math.Round(re);
                    }
                    result.Text = re.ToString();
                }
                else result.Text = "숫자를 쓰세요";
            }
            else result.Text = "숫자를 쓰세요";
        }

        private void sub_Click(object sender, EventArgs e)
        {
            float num1, num2, re;
            if (float.TryParse(tbxnum1.Text, out num1))
            {
                if (float.TryParse(tbxnum2.Text, out num2))
                {
                    re = num1 - num2;
                    if (re % 1 == 0)
                    {
                        re = (int)Math.Round(re);
                    }
                    result.Text = re.ToString();
                }
                else result.Text = "숫자를 쓰세요";
            }
            else result.Text = "숫자를 쓰세요";
        }

        private void mul_Click(object sender, EventArgs e)
        {
            float num1, num2, re;
            if (float.TryParse(tbxnum1.Text, out num1))
            {
                if (float.TryParse(tbxnum2.Text, out num2))
                {
                    re = num1 * num2;
                    if (re % 1 == 0)
                    {
                        re = (int)Math.Round(re);
                    }
                    result.Text = re.ToString();
                }
                else result.Text = "숫자를 쓰세요";
            }
            else result.Text = "숫자를 쓰세요";
        }

        private void div_Click(object sender, EventArgs e)
        {
            float num1, num2, re;
            if (float.TryParse(tbxnum1.Text, out num1))
            {
                if (float.TryParse(tbxnum2.Text, out num2))
                {
                    re = num1 / num2;
                    if (re % 1 == 0)
                    {
                        re = (int)Math.Round(re);
                    }
                    result.Text = re.ToString();
                }
                else result.Text = "숫자를 쓰세요";
            }
            else result.Text = "숫자를 쓰세요";
        }
    }
}