9 Replies - 2255 Views - Last Post: 21 March 2016 - 02:08 PM

#1 granitvit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 22-August 15

Help with a calculator made with forms

Posted 04 September 2015 - 06:07 AM

Hi, I'm supposed to make a graphical calculator for my assignment. I'ts working so far with addition, but I can't figure out how to add subtraction and multiplication. Any pointers would be fantastic. I'm using Visual C++ 2010 and Windows 8.1.

#pragma once

namespace Uppg3 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		int sum; // Håller reda på summan för uträknade tal 
		String ^ newNr;// Innehåller talet som användaren skriver just nu

		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			sum = 0;
			newNr = "";
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::Button^  button0;
	private: System::Windows::Forms::Button^  buttonClear;
	private: System::Windows::Forms::Button^  buttonAdd;
	private: System::Windows::Forms::Button^  buttonSub;
	private: System::Windows::Forms::Button^  buttonMul;
	private: System::Windows::Forms::Button^  buttonSummarize;
	private: System::Windows::Forms::MaskedTextBox^  textBox1;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->button0 = (gcnew System::Windows::Forms::Button());
			this->buttonClear = (gcnew System::Windows::Forms::Button());
			this->buttonAdd = (gcnew System::Windows::Forms::Button());
			this->buttonSub = (gcnew System::Windows::Forms::Button());
			this->buttonMul = (gcnew System::Windows::Forms::Button());
			this->buttonSummarize = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(12, 58);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(43, 36);
			this->button1->TabIndex = 0;
			this->button1->Text = L"1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(61, 58);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(43, 36);
			this->button2->TabIndex = 1;
			this->button2->Text = L"2";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(110, 58);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(43, 36);
			this->button3->TabIndex = 2;
			this->button3->Text = L"3";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(12, 100);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(43, 36);
			this->button4->TabIndex = 3;
			this->button4->Text = L"4";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(61, 100);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(43, 36);
			this->button5->TabIndex = 4;
			this->button5->Text = L"5";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(110, 100);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(43, 36);
			this->button6->TabIndex = 5;
			this->button6->Text = L"6";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(12, 142);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(43, 36);
			this->button7->TabIndex = 6;
			this->button7->Text = L"7";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// button8
			// 
			this->button8->Location = System::Drawing::Point(61, 142);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(43, 36);
			this->button8->TabIndex = 7;
			this->button8->Text = L"8";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// button9
			// 
			this->button9->Location = System::Drawing::Point(110, 142);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(43, 36);
			this->button9->TabIndex = 8;
			this->button9->Text = L"9";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// button0
			// 
			this->button0->Location = System::Drawing::Point(61, 184);
			this->button0->Name = L"button0";
			this->button0->Size = System::Drawing::Size(43, 36);
			this->button0->TabIndex = 9;
			this->button0->Text = L"0";
			this->button0->UseVisualStyleBackColor = true;
			this->button0->Click += gcnew System::EventHandler(this, &Form1::button0_Click);
			// 
			// buttonClear
			// 
			this->buttonClear->Location = System::Drawing::Point(159, 58);
			this->buttonClear->Name = L"buttonClear";
			this->buttonClear->Size = System::Drawing::Size(43, 36);
			this->buttonClear->TabIndex = 10;
			this->buttonClear->Text = L"C";
			this->buttonClear->UseVisualStyleBackColor = true;
			this->buttonClear->Click += gcnew System::EventHandler(this, &Form1::buttonClear_Click);
			// 
			// buttonAdd
			// 
			this->buttonAdd->Location = System::Drawing::Point(159, 100);
			this->buttonAdd->Name = L"buttonAdd";
			this->buttonAdd->Size = System::Drawing::Size(43, 36);
			this->buttonAdd->TabIndex = 11;
			this->buttonAdd->Text = L"+";
			this->buttonAdd->UseVisualStyleBackColor = true;
			this->buttonAdd->Click += gcnew System::EventHandler(this, &Form1::buttonAdd_Click);
			// 
			// buttonSub
			// 
			this->buttonSub->Location = System::Drawing::Point(159, 142);
			this->buttonSub->Name = L"buttonSub";
			this->buttonSub->Size = System::Drawing::Size(43, 36);
			this->buttonSub->TabIndex = 12;
			this->buttonSub->Text = L"-";
			this->buttonSub->UseVisualStyleBackColor = true;
			this->buttonSub->Click += gcnew System::EventHandler(this, &Form1::buttonSub_Click);
			// 
			// buttonMul
			// 
			this->buttonMul->Location = System::Drawing::Point(159, 184);
			this->buttonMul->Name = L"buttonMul";
			this->buttonMul->Size = System::Drawing::Size(43, 36);
			this->buttonMul->TabIndex = 13;
			this->buttonMul->Text = L"x";
			this->buttonMul->UseVisualStyleBackColor = true;
			// 
			// buttonSummarize
			// 
			this->buttonSummarize->Location = System::Drawing::Point(110, 184);
			this->buttonSummarize->Name = L"buttonSummarize";
			this->buttonSummarize->Size = System::Drawing::Size(43, 36);
			this->buttonSummarize->TabIndex = 14;
			this->buttonSummarize->Text = L"=";
			this->buttonSummarize->UseVisualStyleBackColor = true;
			this->buttonSummarize->Click += gcnew System::EventHandler(this, &Form1::buttonSummarize_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(12, 21);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(190, 20);
			this->textBox1->TabIndex = 15;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(218, 228);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->buttonSummarize);
			this->Controls->Add(this->buttonMul);
			this->Controls->Add(this->buttonSub);
			this->Controls->Add(this->buttonAdd);
			this->Controls->Add(this->buttonClear);
			this->Controls->Add(this->button0);
			this->Controls->Add(this->button9);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->button7);
			this->Controls->Add(this->button6);
			this->Controls->Add(this->button5);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: void AddDigit(String ^ nr)
        {
            textBox1->AppendText(nr); // Lägg till numret i textboxen
            newNr += nr; // Lägg till numret i talet som användaren skriver nu
        }
	private: void Summarize()
        {
            if(newNr != "")
			{
                sum = sum + Convert::ToInt32(newNr); // Räkna ut summa
                newNr = ""; // Återställ så användaren kan skriva ett nytt tal
			}
        }
	
	

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("1");
			 }
	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("2");
			 }
	private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("3");
			 }
	private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("4");
			 }
	private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("5");
			 }
	private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("6");
			 }
	private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("7");
			 }
	private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("8");
			 }
	private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("9");
			 }
	private: System::Void button0_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("0");
			 }
	private: System::Void buttonAdd_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				Summarize();
				textBox1->Text = sum + "+"; // Sätt textboxen rätt
			 }
	private: System::Void buttonSummarize_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				Summarize();
				textBox1->Text = sum.ToString();
			 }
	private: System::Void buttonClear_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				sum = 0;
				newNr = "";
				textBox1->Text = "";
			 }
	private: System::Void buttonSub_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
			
				Summarize();
				textBox1->Text = sum + "-";
			 }
};
}




Is This A Good Question/Topic? 0
  • +

Replies To: Help with a calculator made with forms

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Help with a calculator made with forms

Posted 04 September 2015 - 06:35 AM

you could have a variable (called say operator1) wihich is set when your +, -, button is clicked is set (+ =1, - = 2, etc)
in your Summarize() method you could then use a switch to select the operation to be performed, e.g.
	switch (operator1)
	{ 
	case 1: sum = sum + Convert::ToInt32(newNr); break; // Räkna ut summa
	case 2: sum = sum - Convert::ToInt32(newNr); break;
	}


This post has been edited by horace: 04 September 2015 - 06:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 granitvit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 22-August 15

Re: Help with a calculator made with forms

Posted 04 September 2015 - 07:19 AM

Thanks, I see what you mean. I'm pretty new to programming so how would you do the variable and where would you put it? Should I put it in the constructor or somewhere else?
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1378
  • View blog
  • Posts: 4,320
  • Joined: 20-March 10

Re: Help with a calculator made with forms

Posted 04 September 2015 - 07:36 AM

Moving to CLI/C++ forum, as this is CLI/C++ code.
Was This Post Helpful? 0
  • +
  • -

#5 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Help with a calculator made with forms

Posted 04 September 2015 - 08:29 AM

View Postgranitvit, on 04 September 2015 - 03:19 PM, said:

Thanks, I see what you mean. I'm pretty new to programming so how would you do the variable and where would you put it? Should I put it in the constructor or somewhere else?

you would make is a class variable,e.g.
public ref class Form1 : public System::Windows::Forms::Form
{
public:
	int sum; // Håller reda på summan för uträknade tal 
	int operator1;


initialse it in the constructor and then set it in the event handlers, e.g. something along the lines of
	private: System::Void buttonSub_Click(System::Object^  sender, System::EventArgs^  e) 
	{
		Summarize();
		textBox1->Text = sum + "-";
		operator1=2;
}


clearly some work is still needed to make it operate correctly

This post has been edited by horace: 04 September 2015 - 08:35 AM

Was This Post Helpful? 0
  • +
  • -

#6 granitvit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 22-August 15

Re: Help with a calculator made with forms

Posted 06 September 2015 - 03:23 AM

Sorry for the late reply, but am I on the right track here?
Getting a few errors:
error C2059: syntax error : 'switch'
error C2334: unexpected token(s) preceding '{'; skipping apparent function body

#pragma once

namespace Uppg3 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		int sum; // Håller reda på summan för uträknade tal 
		String ^ newNr;// Innehåller talet som användaren skriver just nu
		int operation1;

		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			sum = 0;
			newNr = "";
			operation1;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Button^  button8;
	private: System::Windows::Forms::Button^  button9;
	private: System::Windows::Forms::Button^  button0;
	private: System::Windows::Forms::Button^  buttonClear;
	private: System::Windows::Forms::Button^  buttonAdd;
	private: System::Windows::Forms::Button^  buttonSub;
	private: System::Windows::Forms::Button^  buttonMul;
	private: System::Windows::Forms::Button^  buttonSummarize;
	private: System::Windows::Forms::MaskedTextBox^  textBox1;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->button3 = (gcnew System::Windows::Forms::Button());
			this->button4 = (gcnew System::Windows::Forms::Button());
			this->button5 = (gcnew System::Windows::Forms::Button());
			this->button6 = (gcnew System::Windows::Forms::Button());
			this->button7 = (gcnew System::Windows::Forms::Button());
			this->button8 = (gcnew System::Windows::Forms::Button());
			this->button9 = (gcnew System::Windows::Forms::Button());
			this->button0 = (gcnew System::Windows::Forms::Button());
			this->buttonClear = (gcnew System::Windows::Forms::Button());
			this->buttonAdd = (gcnew System::Windows::Forms::Button());
			this->buttonSub = (gcnew System::Windows::Forms::Button());
			this->buttonMul = (gcnew System::Windows::Forms::Button());
			this->buttonSummarize = (gcnew System::Windows::Forms::Button());
			this->textBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(12, 58);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(43, 36);
			this->button1->TabIndex = 0;
			this->button1->Text = L"1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// button2
			// 
			this->button2->Location = System::Drawing::Point(61, 58);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(43, 36);
			this->button2->TabIndex = 1;
			this->button2->Text = L"2";
			this->button2->UseVisualStyleBackColor = true;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// button3
			// 
			this->button3->Location = System::Drawing::Point(110, 58);
			this->button3->Name = L"button3";
			this->button3->Size = System::Drawing::Size(43, 36);
			this->button3->TabIndex = 2;
			this->button3->Text = L"3";
			this->button3->UseVisualStyleBackColor = true;
			this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
			// 
			// button4
			// 
			this->button4->Location = System::Drawing::Point(12, 100);
			this->button4->Name = L"button4";
			this->button4->Size = System::Drawing::Size(43, 36);
			this->button4->TabIndex = 3;
			this->button4->Text = L"4";
			this->button4->UseVisualStyleBackColor = true;
			this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
			// 
			// button5
			// 
			this->button5->Location = System::Drawing::Point(61, 100);
			this->button5->Name = L"button5";
			this->button5->Size = System::Drawing::Size(43, 36);
			this->button5->TabIndex = 4;
			this->button5->Text = L"5";
			this->button5->UseVisualStyleBackColor = true;
			this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
			// 
			// button6
			// 
			this->button6->Location = System::Drawing::Point(110, 100);
			this->button6->Name = L"button6";
			this->button6->Size = System::Drawing::Size(43, 36);
			this->button6->TabIndex = 5;
			this->button6->Text = L"6";
			this->button6->UseVisualStyleBackColor = true;
			this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
			// 
			// button7
			// 
			this->button7->Location = System::Drawing::Point(12, 142);
			this->button7->Name = L"button7";
			this->button7->Size = System::Drawing::Size(43, 36);
			this->button7->TabIndex = 6;
			this->button7->Text = L"7";
			this->button7->UseVisualStyleBackColor = true;
			this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
			// 
			// button8
			// 
			this->button8->Location = System::Drawing::Point(61, 142);
			this->button8->Name = L"button8";
			this->button8->Size = System::Drawing::Size(43, 36);
			this->button8->TabIndex = 7;
			this->button8->Text = L"8";
			this->button8->UseVisualStyleBackColor = true;
			this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
			// 
			// button9
			// 
			this->button9->Location = System::Drawing::Point(110, 142);
			this->button9->Name = L"button9";
			this->button9->Size = System::Drawing::Size(43, 36);
			this->button9->TabIndex = 8;
			this->button9->Text = L"9";
			this->button9->UseVisualStyleBackColor = true;
			this->button9->Click += gcnew System::EventHandler(this, &Form1::button9_Click);
			// 
			// button0
			// 
			this->button0->Location = System::Drawing::Point(61, 184);
			this->button0->Name = L"button0";
			this->button0->Size = System::Drawing::Size(43, 36);
			this->button0->TabIndex = 9;
			this->button0->Text = L"0";
			this->button0->UseVisualStyleBackColor = true;
			this->button0->Click += gcnew System::EventHandler(this, &Form1::button0_Click);
			// 
			// buttonClear
			// 
			this->buttonClear->Location = System::Drawing::Point(159, 58);
			this->buttonClear->Name = L"buttonClear";
			this->buttonClear->Size = System::Drawing::Size(43, 36);
			this->buttonClear->TabIndex = 10;
			this->buttonClear->Text = L"C";
			this->buttonClear->UseVisualStyleBackColor = true;
			this->buttonClear->Click += gcnew System::EventHandler(this, &Form1::buttonClear_Click);
			// 
			// buttonAdd
			// 
			this->buttonAdd->Location = System::Drawing::Point(159, 100);
			this->buttonAdd->Name = L"buttonAdd";
			this->buttonAdd->Size = System::Drawing::Size(43, 36);
			this->buttonAdd->TabIndex = 11;
			this->buttonAdd->Text = L"+";
			this->buttonAdd->UseVisualStyleBackColor = true;
			this->buttonAdd->Click += gcnew System::EventHandler(this, &Form1::buttonAdd_Click);
			// 
			// buttonSub
			// 
			this->buttonSub->Location = System::Drawing::Point(159, 142);
			this->buttonSub->Name = L"buttonSub";
			this->buttonSub->Size = System::Drawing::Size(43, 36);
			this->buttonSub->TabIndex = 12;
			this->buttonSub->Text = L"-";
			this->buttonSub->UseVisualStyleBackColor = true;
			this->buttonSub->Click += gcnew System::EventHandler(this, &Form1::buttonSub_Click);
			// 
			// buttonMul
			// 
			this->buttonMul->Location = System::Drawing::Point(159, 184);
			this->buttonMul->Name = L"buttonMul";
			this->buttonMul->Size = System::Drawing::Size(43, 36);
			this->buttonMul->TabIndex = 13;
			this->buttonMul->Text = L"x";
			this->buttonMul->UseVisualStyleBackColor = true;
			this->buttonMul->Click += gcnew System::EventHandler(this, &Form1::buttonMul_Click);
			// 
			// buttonSummarize
			// 
			this->buttonSummarize->Location = System::Drawing::Point(110, 184);
			this->buttonSummarize->Name = L"buttonSummarize";
			this->buttonSummarize->Size = System::Drawing::Size(43, 36);
			this->buttonSummarize->TabIndex = 14;
			this->buttonSummarize->Text = L"=";
			this->buttonSummarize->UseVisualStyleBackColor = true;
			this->buttonSummarize->Click += gcnew System::EventHandler(this, &Form1::buttonSummarize_Click);
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(12, 21);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(190, 20);
			this->textBox1->TabIndex = 15;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(218, 228);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->buttonSummarize);
			this->Controls->Add(this->buttonMul);
			this->Controls->Add(this->buttonSub);
			this->Controls->Add(this->buttonAdd);
			this->Controls->Add(this->buttonClear);
			this->Controls->Add(this->button0);
			this->Controls->Add(this->button9);
			this->Controls->Add(this->button8);
			this->Controls->Add(this->button7);
			this->Controls->Add(this->button6);
			this->Controls->Add(this->button5);
			this->Controls->Add(this->button4);
			this->Controls->Add(this->button3);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }
	private: void AddDigit(String ^ nr)
        {
            textBox1->AppendText(nr); // Lägg till numret i textboxen
            newNr += nr; // Lägg till numret i talet som användaren skriver nu
        }
	private: void Summarize()
        {
            if(newNr != "")
			{
               //sum = sum + Convert::ToInt32(newNr); // Räkna ut summa
               newNr = ""; // Återställ så användaren kan skriva ett nytt tal
			}
		}		
	private: switch (operation1)
			{
				case 1: sum = sum + Convert::ToInt32(newNr); break;
				case 2: sum = sum - Convert::ToInt32(newNr); break;
				case 3: sum = sum * Convert::ToInt32(newNr); break;
			}
	

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("1");
			 }
	private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("2");
			 }
	private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("3");
			 }
	private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("4");
			 }
	private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("5");
			 }
	private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("6");
			 }
	private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("7");
			 }
	private: System::Void button8_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("8");
			 }
	private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("9");
			 }
	private: System::Void button0_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				AddDigit("0");
			 }
	private: System::Void buttonAdd_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				Summarize();
				textBox1->Text = sum + "+"; // Sätt textboxen rätt
				operation1 = 1;
			 }
	private: System::Void buttonSummarize_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				Summarize();
				textBox1->Text = sum.ToString();
			 }
	private: System::Void buttonClear_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				sum = 0;
				newNr = "";
				textBox1->Text = "";
			 }
	private: System::Void buttonSub_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
				Summarize();
				textBox1->Text = sum + "-";
				operation1 = 2;
			 }
	private: System::Void buttonMul_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
				Summarize();
				textBox1->Text = sum + "x";
				operation1 = 3;
		 }
};
}


Was This Post Helpful? 0
  • +
  • -

#7 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Help with a calculator made with forms

Posted 06 September 2015 - 04:01 AM

remove the private: in front of the switch()
Was This Post Helpful? 0
  • +
  • -

#8 granitvit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 22-August 15

Re: Help with a calculator made with forms

Posted 06 September 2015 - 07:33 AM

I did that and I'm still getting those two errors from the switch ().
Was This Post Helpful? 0
  • +
  • -

#9 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Help with a calculator made with forms

Posted 06 September 2015 - 08:47 AM

you have to sort out the { ... } in the function
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5899
  • View blog
  • Posts: 20,142
  • Joined: 05-May 12

Re: Help with a calculator made with forms

Posted 21 March 2016 - 02:08 PM

Moving to C++/CLI...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1