🔒 Closed Help po Calculator

Status
Not open for further replies.

Murrzz

Honorary Poster
Gumawa po ako ng Calculator using C# hindi ko po magawa yung gantong operations 3+4+5-6*3 , Yung nagawa ko po is click pa yung '=' sign to compute.
Ito po yung pic:
1613629917240.png


Ito po yung Code ko
C#:
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 Calculator
{
    public partial class Form1 : Form
    {
        int val=0;
        char op;
       Boolean  cho =true ;

        public Form1()
        {
            InitializeComponent();
        }

      

        private void btnAdd_Click(object sender, EventArgs e)
        {

                op = '+';
                val = int.Parse(txtVal.Text);
                txtVal.Text = "";
            
        
        }
      
        private void btnSubt_Click(object sender, EventArgs e)
        {
          
                op = '-';
                val = int.Parse(txtVal.Text);
                txtVal.Text = "";
          
        }

        private void btnDiv_Click(object sender, EventArgs e)
        {
            
                op = '/';
                val = int.Parse(txtVal.Text);
                txtVal.Text = "";
        

        }

        private void btnMult_Click(object sender, EventArgs e)
        {
        
                op = '*';
                val = int.Parse(txtVal.Text);
                txtVal.Text = "";
        
        }
        private void btnEqual_Click(object sender, EventArgs e)
        {
            Condition();
        }
        public void Condition()
        {
            if (cho == true)
            {
                if (op == '+')
                {
                    val += int.Parse(txtVal.Text);
                    txtVal.Text = val.ToString();
                    
                }
                else if (op == '-')
                {
                    val = val - int.Parse(txtVal.Text);
                    txtVal.Text = val.ToString();
                    
                }
                else if (op == '/')
                {
                    val = val / int.Parse(txtVal.Text);
                    txtVal.Text = val.ToString();
                   
                }
                else if (op == '*')
                {
                    val = val * int.Parse(txtVal.Text);
                    txtVal.Text = val.ToString();
                    
                }
            }
        }

      
      
    
    }
}
 
Status
Not open for further replies.

About this Thread

  • 23
    Replies
  • 1K
    Views
  • 7
    Participants
Last reply from:
cetmyeval69

Trending Topics

Online now

Members online
1,088
Guests online
1,411
Total visitors
2,499

Forum statistics

Threads
2,272,458
Posts
28,942,834
Members
1,237,208
Latest member
Vicodoc77
Back
Top