I would have thought a use of macros and templates would be the best combination of speed efficiency and usefulness and simplicity.
Code:
#include <iostream>
#define cube(x) ((x)*(x)*(x))
template<class x> x add(x aValue, x bValue)
{
x result;
aValue + bValue;
return(result);
}
// we have to declare the type use in replace of
// x template for our function(forgot the proper term, overloading might be it even
// though I think in the case of templates it's different)
int add(int, int);
double add(double, double);
int main()
using namespace std;
{
char input[];
cout << " 5.5 plus 6.8 is... " << add(5.5, 6.8) << endl;
cout << "6 plus 8 is" << add(6, 8) << endl;
cout << "9 plus 12 cubed is" << cube(add(9,12)) << endl;
cout << "Input a number\n";
cout << "Bye!~\n";
// or maybe a cin.get for a pause I don't encourage the use of
// SYSTEM("PAUSE") since it's specific to the VC++ compiler
return 0;
something like that, take advantage of some OOP instead of having to make completely separate functions and etc. You can add the cin stuff to it and all that. char input[] can be an effective way to get values since there's some library functions (I forget, look in the generic <string> C++ styled header) that can convert char input into int and etc.
C has string.h with support for things like
Code:
atof(char*)
// short for ansi to float, but actually is to double
atoi(char*)
// short for ansi to int
// For accurate error testing remember to implement something to keep
// char constants from input
but I'm not sure about them since their might be a more up to date counter-part in the C++ string header (it lacks the .h extension) Nevertheless use your own methods if you think they're better (that wasn't sass, really if you think they're better then...).
I might make some calculator source myself, it should be professional not only taking two arguments at a time =d the only thing I'm thinking of right now is something with operator overloading for some reason.