algebra calculator

i dont know how to do this but, i need some thing (calculator) where the user types in the whole problem in cluding operators and the program calculates the thing and the problem can be any amount long... is this possible?
help me out if it is please.
Can you give more details?
Why don't you write a program which calls a function that converts your infix expression to postfix notation and then pass this postfix version of your expression to a function which evaluates it and gives result. You can check any good Data Structure book for both these tasks. Both these functions will you use stack, so check the stack chapter in the book, if infix-postfix type separate chapter is not included in the book.
Your expression will be input using a string, for a beginner its a tough task but you will learn a lot of things while reading all this.
where would i learn how to do this...
and more details please
and what book are you talking about...
i am really confused
Last edited on
You need to write a simple parser along with the grammar that will interpret the user's input. I had to write something very similar. (a calculator) I recommend Stroustrup's Principles of programming. It is a great text book and that particular problem is covered in detail. I warn you though, writing a parser/grammar/tokenizer is not very simple. If you have never seen this concept it will take you a while to swallow it.
It works but y is it so slow???


code:


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <std_lib_facilities.h>
int main()
{
    cout << "Enter the expression we can handle + ,-,* and /";
    double lval = 0;
    double rval;
    char op;
    double res;
    cin >> lval;
    if (!cin) error ("no first operand");




    while (cin >> op) {
          cin >> rval;
      if (!cin) error ("no second operand");    
      switch (op) {


    case '+':
    lval += rval;
    break;
    
    case '-':
    lval -= rval;
    break;
    
    case '*':
    lval *= rval;
    break;
    
    case '/':
    lval /= rval;
    break;
    
default:
   cout << "Result:" << lval << '\n';
   keep_window_open();
   return 0;
                    }
           }
error ("Bad Expression");
}
Topic archived. No new replies allowed.