Ok...
First things first:
#include <iostream.h>
is outdated... the new standard is this:
#include <iostream>
The problem with the new standard is, you need to do a "using" declaration for items you want to use from the includes. An example follows:
using std::cin;
using std::cout;
using std::endl;
Some people teach you to use the following instead:
using namespace std;
The if you do:
#include <iostream>
using namespace std;
you are doing the equivalent of the old style:
#include <iostream.h>
This is not normally desirable. People can argue this, but I've already defended my stance on this syntax in a previous thread.
Now for the problem you asked about:
when you do "cin >> calculation" all it grabs is the first input that can fit inside the variable. In other words... when the user types "4 + 5" all that gets stored is the 4...
What you'll need to do is learn to grab a string from the command line (or learn to grab one character at a time until you reach a newline...)
Calculators aren't as easy as you would think... the easiest calculator to implement is a reverse polish notation calculator which uses a stack to compute the answer...
If you can write that, you can write a program to convert the input into reverse polish notation (again using a stack) and then use your RPN calculator to do the computation......


Reply With Quote
I do try to explain why something is "BAD(TM)" and "GOOD(TM)" if I see something like that, but if I don't explain myself well enough, you'll need to let me know so I can reword the explanation 
Bookmarks