I've just started C++ and I don't fully understand it yet. I made the following application (in Borland) and my teacher called it dangerous coding and said that coding like this might give me problems in the future.
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ten.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString s, t;
s = this->A->Text;
t = this->B->Text;
this->AdivB->Text = s/t;
this->AmodB->Text = s%t;
}
//---------------------------------------------------------------------------
He told me to use something like:
Code:
int number1
number1 = s.ToInt();
So I tried this:
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ten.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int A
A = s.ToInt();
int B
B = t.ToInt();
this->AdivB->Text = s/t;
this->AmodB->Text = s%t;
}
//---------------------------------------------------------------------------
Shamefully this didn't work. Could someone tell me what I'm doing wrong and explain why?
Thanks in advance,
Sam Granger