말씀하신대로 코드를 Button클릭 이벤트로 모두 옮기니 원활히 실행이 됩니다.
그런데 두번째 수를 0으로 하고 나누기연산을 하면 코드에서 처럼 You have to put non-zero numbers ! 하고 팝업창을 띄우려고 하는데 실행을 시켰더니 Project Assignment2_p.exx raised exception class EZeroDivide with message 'Floating point division by zero' 하고 에러가 뜹니다.... 두번째 수에 0을 입력하는데도 나누기 연산자가 실행되는거 같네요,,,, 문제가 무엇일까요 ㅠ
: :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double no1,no2;
AnsiString oprator;
no1=num1->Text.ToDouble();
no2=num2->Text.ToDouble();
oprator=oprtor->Text;
if (oprator=='+') {
this->result->Caption=AnsiString(no1+no2);
}
else if (oprator=='-') {
this->result->Caption=AnsiString(no1-no2);
}
else if (oprator=='/')
{
if (num2!=0) {
this->result->Caption=AnsiString(no1/no2);
}
else if (num2 ==0)
{ShowMessage(" You have to put non-zero numbers"); }
}
}
|