473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

calculator in c#...help plz

1
hello...im trying to make a simple calculator on c# i have written this code as seen under but i cant figure out how to initialize the values from the buttons the add function is working fine but it wont read values from the buttons it keeps on adding the default value 0 (number1+number2)...help me out here plz...thanx





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

namespace Oop
{

public partial class Form1 : Form
{
public Form1()

{

InitializeComponent();
}
public int number1;
public int number2;
public int result;
public void Form1_Load(object sender, EventArgs e)
{




}

private void button3_Click(object sender, EventArgs e)
{

}

private void button13_Click(object sender, EventArgs e)
{

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

{



}
}

private void btn9_Click(object sender, EventArgs e)
{

int number1 = 9;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number1);
//btn9.Text = Convert.ToString(number1);









}

private void btn8_Click(object sender, EventArgs e)
{
int number2 = 8;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
//btn8.Text = Convert.ToString(number2);
}

private void btn7_Click(object sender, EventArgs e)
{
int number1 = 7;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number1);
//btn7.Text = Convert.ToString(number1);
}

private void btn6_Click(object sender, EventArgs e)
{
int number2 = 6;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
//btn6.Text = Convert.ToString(number2);
}

private void btn5_Click(object sender, EventArgs e)
{
int number1 = 5;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number1);
// btn5.Text = Convert.ToString(number1);
}

private void btn4_Click(object sender, EventArgs e)
{
int number2 = 4;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
// btn4.Text = Convert.ToString(number2);
}

private void btn3_Click(object sender, EventArgs e)
{
int number1 = 3;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number1);
// btn3.Text = Convert.ToString(number1);
//Console.ReadLine(number1);
}

private void btn2_Click(object sender, EventArgs e)
{
int number2 = 2;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
//btn2.Text = Convert.ToString(number2);
//number2 = Convert.ToString(Console.ReadLine());
}

private void btn1_Click(object sender, EventArgs e)
{
int number1 = 1;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number1);
//btn1.Text = Convert.ToString(number1);
}

private void btn0_Click(object sender, EventArgs e)
{
int number2 = 0;
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
//btn0.Text = Convert.ToString(number2);
}

private void btndivide_Click(object sender, EventArgs e)
{

}

private void btnmultiply_Click(object sender, EventArgs e)
{

}

private void btnsubtract_Click(object sender, EventArgs e)
{

}

private void btnequal_Click(object sender, EventArgs e)
{

//btnequal.Show = Convert.ToString(result);
txtinput.Text = Convert.ToString(result);
//btnequal.Text = Convert.ToString(result);




}

private void btnadd_Click(object sender, EventArgs e)
{



result = number1 + number2;




//txtinput.Text = Convert.ToString(number2);
//btnadd.Text = Convert.ToString(result);
}
}
}
Sep 22 '06 #1
1 3735
hmm.. very confusing code if you ask me..


InitializeComponent(); where is the method?



private void btn8_Click(object sender, EventArgs e)
{
int number2 = 8; <<<<------ This will declare a new varible in btn8_Click but not public.
//Convert.ToString(fnumber);

txtinput.Text = Convert.ToString(number2);
//btn8.Text = Convert.ToString(number2);
}
Sep 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: mwh | last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a calculator with javascript. I can't get this to work: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
2
by: XIII | last post by:
i just created this benefits calculator, but it doesn't work, there is no changes happen after submitting, anyone can help in that?? <html> <head> <title> |||Stocks Calculator||| </title> <style...
3
by: PieMan2004 | last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :) Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
1
by: remya1000 | last post by:
from my system i need to open a calculator in remote machine. and i'm using Vb.net and WMI. i need to pop up the calculator in remote machine, while i run one program in my system. while running in...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.