HELP": Calculator Error??

Hi, I am trying to make a calculator with Visual C++ Express. It just doesn't work? Any help??

// calculator 3.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace calculator3;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

Form1.h file:

#pragma endregion
char of double x, y d;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->label1->Text = "*"; c = '*';
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->label1->Text = "+"; c = '+'
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
this->label1->Text = "-"; c = '-'
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
this->label1->Text = "/"; c = '/';
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
x = System::Convert::ToInt32(this->input1->Text);
y = System::Convert::ToInt32(this->input2->Text);
switch(c)
}
case '*' : d = x*y; break;
case '+' : d = x+y; break;
case '-' : d = x-y; break;
case '/' : d = x/y; break;
}
this->label2->Text = System::Convert::ToString(d);
};
}

It just doesn't work?

In what way? What error(s) are you getting?

I noticed some things that would result in compilation errors:

1. this->label1->Text = "+"; c = '+' //missing semicolon

2. this->label1->Text = "-"; c = '-' //missing semicolon

3.
1
2
switch(c)
}//this should be an opening closing brace 

4.
1
2
3
this->label2->Text = System::Convert::ToString(d);
}; //semicolon not necessary (though won't give an error)
}//If this is the whole Form1.h file, then I don't know what this brace is doing here 

Last edited on
Hi, I fixed the errors you told me... but I still get this

Error	1	error C2144: syntax error : 'double' should be preceded by ';'	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	2	error C2208: 'double' : no members defined using this type	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	4	error C2146: syntax error : missing ';' before identifier 'd'	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	5	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h	189
Error	7	error C2059: syntax error : 'namespace'	C:\Users\Johan\Desktop\cobus project\Calculator asb\Calculator asb\Calculator asb.cpp	6
Error	8	error C2238: unexpected token(s) preceding ';'	C:\Users\Johan\Desktop\cobus project\Calculator asb\Calculator asb\Calculator asb.cpp	6
Error	9	error C1075: end of file found before the left brace '{' at 'c:\users\johan\desktop\cobus project\calculator asb\calculator asb\Form1.h(16)' was matched	C:\Users\Johan\Desktop\cobus project\Calculator asb\Calculator asb\Calculator asb.cpp	19
char of double x, y d;

I'm not sure this is correct either.

I think it should be double x, y, d; If you want them to be doubles.
It still gives the same error??
Did you declare c somewhere, and Text? I can't find it in this code, but it could be in namespace calculator3.
How do you declare it, and where?
Topic archived. No new replies allowed.