Calculator++, Now Available for download on SourceForge!

Status
Not open for further replies.

eXtensible

Baseband Member
Messages
37
Location
Earth
Hi eXtensible here,
I've recently created a calculator app designed to replace the standard Calculator app with a more advanced scientific Calculator.

Here is the Download Link: Calculator++ - Browse Files at SourceForge.net

Just Click "Calculator.exe" To begin the download

It's currently in its developing stages and i'm still working to add better framework and more advanced math functions. I plan to release a newer, more advanced version sometime in July.

Also, for Developers, the Source Code is also available for download. Feel free to develop a plugin or just advance the source code.

To Download the Source Code Just Click "Calculator.cpp"

Any questions, Feel free to repost to this thread

I also Thought I Might Include the current Source code.

Source:
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;
int main()
{
int WhichFunction;
cout << "What would you like to do ? " << endl << "HINT: 1 = add, 2 = subtract, 3 = multiply, 4 = divide, 5 = Sqr. Root," << endl << "6 = Exponents" << endl;
cin >> WhichFunction;
switch(WhichFunction){

case 1:
double a;
cout << "Enter the first number: ";
cin >> a;
double b;
cout << "Enter the second number: ";
cin >> b;
double c;
c = a + b;
cout << "Calculating: " << c << endl;
system("PAUSE");
return 0;
break;

case 2:
double aa;
cout << "Enter the first number: ";
cin >> aa;
double bb;
cout << "Enter the second number: ";
cin >> bb;
double cc;
cc = aa - bb;
cout << "Calculating: " << cc << endl;
system("PAUSE");
return 0;
break;

case 3:
double a3;
cout << "Enter the first number: ";
cin >> a3;
double b3;
cout << "Enter the second number: ";
cin >> b3;
double c3;
c3 = a3 * b3;
cout << "Calculating: " << c3 << endl;
system("PAUSE");
return 0;
break;

case 4:
double a4;
cout << "Enter the first number: ";
cin >> a4;
double b4;
cout << "Enter the second number: ";
cin >> b4;
double c4;
c4 = a4 / b4;
if(a4 > 0){
cout << "Calculating: " << c4 << endl;
}
if(b4 > 0){
cout << "Calculating: " << c4 << endl;
}
if(b4 <= 0){
cout << "You Cannot Divide by Zero " << endl;
}
system("PAUSE");
return 0;
break;

case 5:
double a5;
cout << "Enter Your Number: ";
cin >> a5;
double b5;
b5 = sqrt(a5);
cout << "Calculating: " << b5 << endl;
break;

case 6:
double a6,b6;
cout << "Enter your Number: ";
cin >> a6;
cout << "Enter the Exponent: ";
cin >> b6;
double c6;
c6 = pow(a6,b6);
cout << "Calculating: " << c6 << endl;
break;
default:
cout << "An Error Has Occured, Please try and run the program again. ";
break;
}

system("PAUSE");
return EXIT_SUCCESS;
}
 
So you've got add, subtract, divide and multiply so far? Got a little ways to go before it replaces the standard Calculator app lol ;) good project though!
Don't forget to condense where you can, e.g. instead of going:
double a;
double b;
double c;
you can just go
double a,b,c;

etc. Just makes it easier :thumbsup:
 
Good start! I have some suggestions for you that I hope you will consider in order to become a better programmer.

You might want to add some error handling to your input routines. For instance, what will happen if a user enters a and b as the 2 numbers for any of the math functions? In your divide routine, what happens if a user enters 0 as the second number? Users can and will do strange things.

It's not necessary to have all the variables you are using. All of the math functions use 3 doubles, why not declare them once at the top of your program? In fact, you really don't need the third double.

You used the same variable (a) twice, once as an integer and again as a double. While it works, it's considered poor form and could be a source of confusion. Why not have 2 variables? You should also use more descriptive variable names.

using namespace std;
int main()
{
int WhichFunction;
double FirstNumber, SecondNumber;
cout << "What would you like to do ? " << endl << "HINT: 1 = add, 2 = subtract, 3 = multiply, 4 = divide " << endl;
cin >> WhichFunction;
switch(WhichFunction){
case 1:
cout << "Enter the first number: ";
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
cout << "Calculating: " <<FirstNumber + SecondNumber << endl;
system("PAUSE");
return 0;
break;
case 2:
cout << "Enter the first number: ";
cin >> FirstNumber;
cout << "Enter the second number: ";
cin >> SecondNumber;
cout << "Calculating: " << FirstNumber - SecondNumber << endl;
system("PAUSE");
return 0;
break;
etc...
 
Thanks for the suggestions, I'm in the process of adding some error handling in the division routine, thanks for pointing out that bug, I'll be sure to include it in the next version.
,eXtensible
 
He's talking about C++ and many other languages using the CPU to do decimal calculations. The CPU never returns an exact value when dividing, multiplying etc. There really isn't a true way around it in C++. However, in other languages built from C++ such as Python and PHP, they have data types that support exact calculations. In Python check out the "decimal.decimal" type.
 
Current Source:
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{

int WhichFunction;
cout << "What would you like to do ? " << endl << "HINT: 1 = add, 2 = subtract, 3 = multiply, 4 = divide, 5 = Sqr. Root," << endl << "6 = Exponents, 7 = Pythagorean Theorum" << endl;
cin >> WhichFunction;
switch(WhichFunction){

case 1:
double a;
cout << "Enter the first number: ";
cin >> a;
double b;
cout << "Enter the second number: ";
cin >> b;
double c;
c = a + b;
cout << "Calculating: " << c << endl;
system("PAUSE");
return 0;
break;

case 2:
double aa;
cout << "Enter the first number: ";
cin >> aa;
double bb;
cout << "Enter the second number: ";
cin >> bb;
double cc;
cc = aa - bb;
cout << "Calculating: " << cc << endl;
system("PAUSE");
return 0;
break;

case 3:
double a3;
cout << "Enter the first number: ";
cin >> a3;
double b3;
cout << "Enter the second number: ";
cin >> b3;
double c3;
c3 = a3 * b3;
cout << "Calculating: " << c3 << endl;
system("PAUSE");
return 0;
break;

case 4:
double a4;
cout << "Enter the first number: ";
cin >> a4;
double b4;
cout << "Enter the second number: ";
cin >> b4;
double c4;
c4 = a4 / b4;

if(a4 > 0){
cout << "Calculating: " << c4 << endl;
}

if(b4 > 0){
cout << "Calculating: " << c4 << endl;
}

if(b4 <= 0){
cout << "You Cannot Divide by Zero " << endl;
}
system("PAUSE");
return 0;
break;

case 5:
double a5;
cout << "Enter Your Number: ";
cin >> a5;
double b5;
b5 = sqrt(a5);
cout << "Calculating: " << b5 << endl;
system("PAUSE");
return 0;
break;

case 6:
double a6,b6;
cout << "Enter your Number: ";
cin >> a6;
cout << "Enter the Exponent: ";
cin >> b6;
double c6;
c6 = pow(a6,b6);
cout << "Calculating: " << c6 << endl;
system("PAUSE");
return 0;
break;

case 7:
double a7;
double b7;
double c7;
double x7;
cout << "-----------------------" << endl;
cout << " Pythagorean Theorem" << endl;
cout << "-----------------------" << endl;
cout << " ." << endl;
cout << " . . " << endl;
cout << " a . . c" << endl;
cout << " . . "<< endl;
cout << " . ."<< endl;
cout << " ..........."<< endl;
cout << " b "<< endl;
cout << endl;
cout << "How to: " << endl;
cout << endl;
cout << "When asked for your missing variable type press '0' and then enter." << endl;
cout << endl;
cout << "Equation: a(sqaured) + b(square) = c(squared)" << endl;
cout << endl;
cout << "Please input your 'a' variable: ";
cin >> a7;
cout << "Please input your 'b' variable: ";
cin >> b7;
cout << "Please input your 'c' variable: ";
cin >> c7;

if (c == 0)
{
x7 = (a7*a7) + (b7*b7);
cout << "Your missing length is " << sqrt(x7) << endl;
}

if (a7 == 0)
{
x7 = (c7*c7) - (b7*b7);
cout << "Your missing length is " << sqrt(x7) << endl;
}

if (b7 == 0)
{
x7 = (c7*c7) - (a7*a7);
cout << "Your missing length is " << sqrt(x7) << endl;
}

system("PAUSE");
return 0;
break;

default:
cout << "An Error Has Occured, Please try and run the program again. ";
break;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Also, If anyone has any suggestions for any Theorums, equations, functions, etc. I should use please let me know.
,eXtensible
 
Status
Not open for further replies.
Back
Top Bottom