0% found this document useful (0 votes)
3 views7 pages

C++ Calculator Button Click Events

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

C++ Calculator Button Click Events

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#pragma endregion

int firstnum;

int secondnum;

int result;

int operation;

private: System::Void One_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text=="0")

textdisplay->Text = "1";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "1";

private: System::Void Two_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "2";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "2";

}
}

private: System::Void Three_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "3";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "3";

private: System::Void Four_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "4";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "4";

private: System::Void Five_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "5";

}
else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "5";

private: System::Void Six_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "6";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "6";

private: System::Void Seven_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "7";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "7";

private: System::Void Eight_Click(System::Object^ sender, System::EventArgs^ e) {


if (textdisplay->Text == "0")

textdisplay->Text = "8";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "8";

private: System::Void Nine_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "9";

else

textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "9";

private: System::Void Zero_Click(System::Object^ sender, System::EventArgs^ e) {

if (textdisplay->Text == "0")

textdisplay->Text = "0";

else

{
textdisplay->Text = Convert::ToInt32(textdisplay->Text) + "0";

private: System::Void Clear_Click(System::Object^ sender, System::EventArgs^ e) {

textdisplay->Text = "";

textdisplay->Text = "0";

private: System::Void Plus_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = "0";

operation = '+';

private: System::Void Minus_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = "0";

operation = '-';

private: System::Void Multiply_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = "0";

operation = '*';

private: System::Void Divide_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = "0";

operation = '/';
}

private: System::Void Modulo_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = "0";

operation = '%';

private: System::Void SquareRoot_Click(System::Object^ sender, System::EventArgs^ e) {

firstnum = Convert::ToInt32(textdisplay->Text);

textdisplay->Text = System::Convert::ToString(Math::Sqrt(firstnum));

private: System::Void Equal_Click(System::Object^ sender, System::EventArgs^ e) {

secondnum = Convert::ToInt32(textdisplay->Text);

switch (operation) {

case '+':

result = firstnum + secondnum;

break;

case '-':

result = firstnum - secondnum;

break;

case '*':

result = firstnum * secondnum;

break;

case '/':

result = firstnum / secondnum;

break;

case '%':
if (secondnum != 0) {

result = firstnum % secondnum;

else {

textdisplay->Text = "Error: Division by zero!";

return;

break;

default:

break;

textdisplay->Text = [Link]();

};

You might also like