Hi to all,

THis is my first post here.

I have a project to create a scientific calculator.

i wrote a code and i need some help on how to proceed.
The code i wrote is for +, - , * , /
now i want to continue with x^y, arc,tan etc.

any ideas on how to proceed with these?

Thanks in advance.

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

BOOL IsNumber(AnsiString s)
{
int i;
BOOL itis=true;
for (i=1 ; i<=s.Length() ; i++)
if (!isdigit(s[i]) && s[i]!=',' && s[i]!='-') itis=false;
return itis;
}

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button11Click(TObject *Sender)
{
Form1 -> Close();        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button9Click(TObject *Sender)
{
Edit1 -> Clear();
Edit2 -> Clear();
Edit3 -> Clear();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button10Click(TObject *Sender)
{
Form2 -> ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
Edit3->Text=Edit1->Text.ToDouble() + Edit2->Text.ToDouble();
else
MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
Edit3->Text=Edit1->Text.ToDouble() - Edit2->Text.ToDouble();
else
MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
Edit3->Text=Edit1->Text.ToDouble() * Edit2->Text.ToDouble();
else
MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if (IsNumber(Edit1->Text) && IsNumber(Edit2->Text))
Edit3->Text=Edit1->Text.ToDouble() / Edit2->Text.ToDouble();
else
MessageBox(NULL,"Not a number", "About Form",MB_OK|MB_ICONSTOP);
}
//---------------------------------------------------------------------------

Dani AI

Generated

Good start — you already have the UI hooks for basic ops, so the next steps are (1) wiring the math routines you need, (2) strengthening input parsing and domain checks, and (3) deciding whether to keep the two-edit layout or move to a single-expression approach. ’s framework point matters only for the UI layer; the numeric functions you need are the same idea across compilers.

A practical way to add x^y and inverse trig: convert the edits to doubles, guard the domain, call the appropriate math routine, then convert back to text. Example patterns (VCL-style, not repeating your original operators):

double a = Edit1->Text.ToDouble();
double b = Edit2->Text.ToDouble();

/* x^y with domain check for negative base + fractional exponent */
double intpart;
if (a < 0.0 && std::modf(b, &intpart) != 0.0) {
  ShowMessage("Result is not a real number for negative base with non-integer exponent");
} else {
  Edit3->Text = FloatToStr( pow(a, b) );
}

/* arctan (convert radians to degrees if needed) */
double v = Edit1->Text.ToDouble();
double angRad = atan(v);
Edit3->Text = FloatToStr( angRad * 180.0 / acos(-1.0) );

Replace conversion/format calls with whatever your framework provides. Replace atan with atan2(y,x) when you need quadrant-aware angles.

Validation and robustness tips: stop using brittle character tests. Try converting the string (TryStrToFloat / std::stod with try/catch) and handle failures. Always check domains (sqrt/log inputs, asin/acos in [-1,1], division by zero). Consider using a small expression parser (muParser/ExprTk or similar) if you want users to enter full formulas rather than two separate fields. Finally, add unit tests for edge cases (NaN, +/-inf, locale decimal separators, very large/small exponents).

but the code you put, is a Borland's VCL code. it's not a Visual C++ code!
but I think programming with Borland's C++Builder is easier! ;)
about arctan, etc there are appropriate functions in math.h

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.