Calculator Tutorial
May 15, 2011 at 7:04pm UTC
Sorry for the re-post. This is a tutorial on how to make a calculator. Not just a basic calculator, basically a graphing calculator without the graphing functions. I also will say, posting for this tutorial may be slow at first (I'm just adding the final touches on my Yahtzee game), but don't worry, I'll get it posted. So, let's start.
Step 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include <cstdlib>
#include <iostream>
#include <math.h> //for shortening some functions
#include <vector> //we will use vectors instead of switch function
#include <valarray> //for some functions we will use valarrays instead of vectors
using namespace std;
double basfunc(double x, double y) //basic functions
{
double add, sub, mult, div ; //add, subtract, multiply, and divide
int operbf ; //operation for basic functions
cout<<"Enter two numbers." <<endl ;
cin>> x ;
cin>> y ;
add=x+y ;
sub=x-y ;
mult=x*y ;
div=x/y ;
vector<double > BasFunc ;
BasFunc.push_back(add) ; //adds add
BasFunc.push_back(sub) ; //adds subtract
BasFunc.push_back(mult) ; //adds multiply
BasFunc.push_back(div) ; //adds divide
cout<<"Enter an operation. 1-add, 2-subtract, 3-multpily, 4-divide." <<endl ;
cin>> operbf ;
cout<<BasFunc[operbf-1] ;
}
That's Step 1, adding our basic functions. Look for Step 2 soon!
Last edited on May 15, 2011 at 7:41pm UTC
May 16, 2011 at 4:09am UTC
Will it evaluate expressions like this correctly: 2+5/(7-3)*5-(1.5*3/9)-8 when its finished?
Topic archived. No new replies allowed.