|
제가 완전 초보인데
계산기를 만들어 볼려고 하는데 이상한 오류가 뜨네요
직접 짠거는 아니고 다른사람들이 작성한 소스 를 응용해서 해봤는데
않되요 고수님들 도와주세요
어떤 오류인지는 그림파일로 올리겠습니다
아래는 제가 응용한 소스입니다
#include <vcl.h>
#pragma hdrstop
#include "computer.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
double Pre_num; //처음입력한 수를 기억
bool Dot_Check;
int InNew; // 처음입력한수를 체크
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Pre_num = 0 ;
Dot_Check = false ;
InNew = true ;
operater = "" ;
Edit1->Font->Style = Edit1->Font->Style << fsBold ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(operater.Length()<1)
sNum1+="1" ;
else
sNum2+="1" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false ;
}
if (Edit1->Text == "0")
Edit1->Text = "1" ;
else
Edit1->Text=Edit1->Text + "1" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(operater.Length()<2)
sNum1+="2" ;
else
sNum2+="2" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "2" ;
else
Edit1->Text=Edit1->Text + "2" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(operater.Length()<3)
sNum1+="3" ;
else
sNum2+="3" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "3" ;
else
Edit1->Text=Edit1->Text + "3" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if(operater.Length()<4)
sNum1+="4" ;
else
sNum2+="4" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "4" ;
else
Edit1->Text=Edit1->Text + "4" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
if(operater.Length()<5)
sNum1+="5" ;
else
sNum2+="5" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "5" ;
else
Edit1->Text=Edit1->Text + "5" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
if(operater.Length()<6)
sNum1+="6" ;
else
sNum2+="6" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "6" ;
else
Edit1->Text=Edit1->Text + "6" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
if(operater.Length()<7)
sNum1+="7" ;
else
sNum2+="7" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "7" ;
else
Edit1->Text=Edit1->Text + "7" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
if(operater.Length()<8)
sNum1+="8" ;
else
sNum2+="8" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "8" ;
else
Edit1->Text=Edit1->Text + "8" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
if(operater.Length()<9)
sNum1+="9" ;
else
sNum2+="9" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
Edit1->Text = "9" ;
else
Edit1->Text=Edit1->Text + "9" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
if(operater.Length()<0)
sNum1+="0" ;
else
sNum2+="0" ;
if (InNew)
{
Edit1->Text = "" ;
InNew = false;
}
if (Edit1->Text == "0")
return ;
else
Edit1->Text=Edit1->Text + "0" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button16Click(TObject *Sender)
{
if (InNew)
{
Edit1->Text = "" ;
InNew = false ;
}
if (Dot_Check) return ;
Edit1->Text = Edit1->Text + "." ;
Dot_Check = true ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)//더하기
{
Pre_num = StrToInt(Edit1->Text) ;
InNew = true ;
Dot_Check = false ;
operater = Button12->Caption ;
Edit1 -> Text = Edit1 -> Text + "+" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button13Click(TObject *Sender)//빼기
{
Pre_num = StrToInt(Edit1->Text) ;
InNew = true ;
Dot_Check = false ;
operater = Button13->Caption ;
Edit1 -> Text = Edit1 -> Text + "-" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button14Click(TObject *Sender)//곱하기
{
Pre_num = StrToInt(Edit1->Text) ;
InNew = true ;
Dot_Check = false ;
operater = Button14->Caption ;
Edit1 -> Text = Edit1 -> Text + "*" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button15Click(TObject *Sender)//나누기
{
Pre_num = StrToInt( Edit1->Text ) ;
InNew = true ;
Dot_Check = false ;
operater = Button15->Caption ;
Edit1 -> Text = Edit1 -> Text + "/" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonClearClick(TObject *Sender)
{
sNum1=sNum2=operater="" ;
Edit1->Clear() ;
Dot_Check = false ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
float fNum1 = StrToFloat( sNum1 ) ;
float fNum2 = StrToFloat( sNum2 ) ;
float fResult ;
if ( operater == '+' )
fResult = fNum1 + fNum2 ;
else if ( operater == '-' )
fResult = fNum1 - fNum2 ;
else if ( operater == '/' )
fResult = fNum1 / fNum2 ;
else if ( operater == '*' )
fResult = fNum1 * fNum2 ;
Edit1->Text = sNum1+ operater + sNum2 + "="+FloatToStr(fResult) ;
|