Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 11th, 2005, 7:07 PM   #1
jl13
Newbie
 
Join Date: Oct 2005
Posts: 2
Rep Power: 0 jl13 is on a distinguished road
Calculator Multiple Operations?

I'm trying to program a basic calculator and have gotten all the operations working. Yet my problem is getting the calculator to perform multiple operations without having to hit the equal button in between each seperate operation. I'm listing the operations, and equal button code along with the global variables I used. If any one could help it would be greatly appreciated. Thanks.

		string operation ="";
		bool newNum = false;
		double numMemory;
		bool decimalPushed =false;

		void ButtonAddClick(object sender, System.EventArgs e)
		{
			operation ="+";
			newNum = true;
			numMemory = Convert.ToDouble(Display.Text);
		}
		
		void ButtonMultiplyClick(object sender, System.EventArgs e)
		{
			operation ="x";
			newNum = true;
			numMemory = Convert.ToDouble(Display.Text);
		}
		
		void ButtonDivideClick(object sender, System.EventArgs e)
		{
			operation ="/";
			newNum = true;
			numMemory = Convert.ToDouble(Display.Text);
		}
		
		void ButtonMinusClick(object sender, System.EventArgs e)
		{
			operation ="-";
			newNum = true;
			numMemory = Convert.ToDouble(Display.Text);
		}
		void ButtonEqClick(object sender, System.EventArgs e)
		{
			if (operation == "+")
			{
				if (newNum)
				{
					numMemory = Convert.ToDouble(Display.Text);
					newNum = false;
				}
				double displayValue = Convert.ToDouble(Display.Text);
				displayValue = numMemory + displayValue;
				Display.Text = displayValue.ToString();
			}
			if (operation == "-")
			{
					if (newNum)
			 {
				 numMemory = Convert.ToDouble(Display.Text);
				 newNum = false;
			 }
				double displayValue = Convert.ToDouble(Display.Text);
				displayValue = numMemory - displayValue;
				Display.Text = displayValue.ToString();
			}
			if (operation == "x")
			{
				if (newNum)
				{
					numMemory = Convert.ToDouble(Display.Text);
					newNum = false;
				}
				double displayValue = Convert.ToDouble(Display.Text);
				displayValue = numMemory * displayValue;
				Display.Text = displayValue.ToString();
			}
			if (operation == "/")
			{
				if (newNum)
				{
					numMemory = Convert.ToDouble(Display.Text);
					newNum = false;
				}
				double displayValue = Convert.ToDouble(Display.Text);
				displayValue = numMemory / displayValue;
				Display.Text = displayValue.ToString();
			}
		}
jl13 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC