감사합니다. 드디어 원활히 실행이 되네요 !!
마지막으로 숫자대신 알파벳이나 문자를 입력할 경우 0으로 바뀌도록 해야하는데
일단 알파벳 입력할 경우라도 해결하게 cctype헤더파일에 있는 isalpha()를 이용하여 아래와같이 해봤는데
여의치 않네요.. 도와주세요ㅠ
-------------------------------------------------------------------------------------: :
: :
: : : :
: :
: : void __fastcall TForm1::Button1Click(TObject *Sender)
{
double no1,no2;
AnsiString oprator;
no1=num1->Text.ToDouble();
no2=num2->Text.ToDouble();
oprator=oprtor->Text;
if (isalpha(no1))
{no1=0;}
if (isalpha(no2))
{no2=0;}
if (oprator=='+') {
this->result->Caption=AnsiString(no1+no2);
}
else if (oprator=='-') {
this->result->Caption=AnsiString(no1-no2);
}
else if (oprator=='*') {
this->result->Caption=AnsiString(no1*no2);
}
else if (oprator=='/')
{
if (no2!=0) {
this->result->Caption=AnsiString(no1/no2);
}
else if (no2==0)
{ShowMessage(" You have to put non-zero numbers"); }
}
}
|