Calculator

I've managed to create a calculator that accepts different operators and any amount of numbers using arrays. However, it doesn't calculate the ( * and / ) before the ( + and - ) which I didn't manage to do. I'd like it to calculate the * and / first, any help would be appreciated.

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
45
46
47
48
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <new>
#include <climits>

using namespace std;
int main(int argc, char **argv)
{	
    double number[50] = { };
    char op[50] = { };

    for(int i=0; i<50; i++)
    {
        cout << "Enter Number";
        cin >> number[i];

        cout << "Enter Operator or \"=\"";
        cin >> op[i];
        if(op[i] == '=')
        {
            break;
        }
    }
    
    double total;
    total = number[0];
    for(int i=0;i<50; i++)
    {
        if(op[i] == '*')
        {
          total = total*number[i+1];
        }
        if(op[i] == '+')
        {
          total = total+number[i+1];
        }        
        if(op[i] == '-')
        {
          total = total-number[i+1];
        }        
        if(op[i] == '/')
        {
          total = total/number[i+1];
        }
    }    
    cout << total;
}
Check out ats15' post here, in a thread on the same topic:

Calculator
http://www.cplusplus.com/forum/beginner/166656/#msg838518

Andy
Nice Link
Topic archived. No new replies allowed.