Jump to content
cp/m

Visual C# - Calculator

Recommended Posts

Visual C# 2008 - Calculator

Soundtrack: BoneyM - Raspoutin

YouTube - Visual C# - Calculator


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_for_Youtube
{
public partial class Form1 : Form
{
// Declaram variabile global ca sa nu trebuiasca sa la declaram in fiecare //functie
double num1;
double num2;
double sum;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//num1 ia valoarea din primul textbox
num1 = double.Parse(textBox1.Text);
//num2 ia valoarea din al doilea textbox
num2 = double.Parse(textBox2.Text);
//sum ia valoarea sumei num1+num2
sum = num1 + num2;
//punem sum in label1, insa mai intai trebuie sa trecem sum din double in string
label1.Text = sum.ToString();
}

private void button2_Click(object sender, EventArgs e)
{
//same thing dar cu "-"
num1 = double.Parse(textBox1.Text);
num2 = double.Parse(textBox2.Text);
sum = num1 - num2;
label1.Text = sum.ToString();
}

private void button3_Click(object sender, EventArgs e)
{
//same thing dar cu "*"
num1 = double.Parse(textBox1.Text);
num2 = double.Parse(textBox2.Text);
sum = num1 * num2;
label1.Text = sum.ToString();
}

private void button4_Click(object sender, EventArgs e)
{
//same thing dar cu "/"
num1 = double.Parse(textBox1.Text);
num2 = double.Parse(textBox2.Text);
sum = num1 / num2;
label1.Text = sum.ToString();
}
}
}

Link to comment
Share on other sites

Imi place muzica si faptul ca mai exista persoane care mai si programeaza ceva aici. Oricat de mic ar fi programul.

@cp/m: hint incearca sa folosesti Double.TryParse ca sa nu-ti crape programul daca introduci un string in loc de numar :) Poti sa-l introduci si intr-un try/catch pentru tratarea exceptiilor.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...