Reputation: 11
Im pretty new to c++ and im building a calculator with the windows forms feature. I have made the UI and the UI consists of the user entering digits into the 2 text boxes and after that then the 2 numbers will be added together but I am having this problem and here is the code
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int ^ FirstNumber = textbox1->Text;
int ^ SecondNumber = textBox3->Text;
int ^ Result = FirstNumber + SecondNumber;
}
Does anyone know a fix?? I am also having an error when I add the two var's together.
Upvotes: 1
Views: 58
Reputation: 2612
You need to convert the Textbox strings to ints also you probably dont want managed pointers to those values. Something like this should work (untested):
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int FirstNumber = System::Convert::ToInt32(textBox1->Text);
int SecondNumber = System::Convert::ToInt32(textBox3->Text);
int Result = FirstNumber + SecondNumber;
}
Edit: As @Robert Harvey pointed out in the comments, the first error is likely because textbox1
likely should have been textBox1
but without seeing the rest of the class code its difficult to say
Upvotes: 1