Hello there, Semi-advanced calculator with multiplication/division/remainder priority

hey there - I am a C++ beginner, and I'm making a semi-advanced calculator which will calculate such things like 2+9*10 and will get 92, not 110.

I need quick help from pros, and I can't compile the C++ code due to libraries such as #include <array> arent supported by g++ or something.
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <iomanip>
#include <cmath>
#include <array>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
	//Nustatymas

	double atmintis;

	double a[100] = {};
	double b[100] = {};
	int kurSudetis[200] = {};
	int kurAtimtis[200] = {};
	int kurApvertimas[200] = {};
	double M;
	int ind2 = 0;
	int ind3 = 0;
	int ind4 = 0;
	int ind;
	double atsakymas;
	char zenklas[300] = {};
	bool lygu = false;
	//Ivedamw reiskini
	cout << "iveskite reiskini. /n" << "Naudokite +, -, *, /, %, a(apvertimas - 1/x) aritmetiniams reiskiniams /n"<< "Atminciai naudokite P(M+), M(M-), S(MS), R(MR), C(MC) /n";
	cout << "apvertimas apvers TIK antraji skaiciu. Bet geriau naudoti dalini tada /, tada dalikli /n";
	while(lygu = false){
		//vedame iki =
		for(int i = 0; i < 101; i++){
			cin >> a[i] >> zenklas[i] >> b[i];
			if(zenklas[i] == '='){
				cout << "pradedame skaiciuoti /n";
				lygu = true;
			}
		}
		
	}
	//Nustateme, kada vartotojas iveda lygybes zenkla
	//O dabar skaiciuojame
	//Dauginame, daliname(for)
	for(int n = 0; n < zenklas.size(); n++){
		//skaiciuojame tol, kol gauname kazka		
		//is pradziu dauginame, daliname, %, 1/x
		switch(zenklas[n]){
			case "*":
				{
					ind = n%2;
					if(ind = 1){
						//Nustatome, ar indeksas yra lyginis, ar nelyginis
						//Numetame atsakyma i B
						b[n] = a[n]*b[n];
					} else {
						//Numetame atsakyma i A
						a[n] = a[n]*b[n];
					}
					n--;
					break;
				}
			case "/": //tas pats, kas virsui, tik sudalijama
				{
					ind = n%2;
					if(ind = 1){
						//Nustatome, ar indeksas yra lyginis, ar nelyginis
						//Numetame atsakyma i B
						b[n] = a[n]/b[n];
					} else {
						//Numetame atsakyma i A
						a[n] = a[n]*b[n];
					}
					n--;
					break;
				}
			case "%": //modulis 
			{
					ind = n%2;
					if(ind = 1){
						//Nustatome, ar indeksas yra lyginis, ar nelyginis
						//Numetame atsakyma i B
						b[n] = fmod(a[n],b[n]);
					} else {
						//Numetame atsakyma i A
						a[n] = fmod(a[n],b[n]);
					}
					n--;
					break;
				}
			case "+":{ //nu va dabar tai rikiuojam veiksmus
			    
				kurSudetis[ind2] = n;
				ind2++;
				break;
			}
			case "-":{
				kurSudetis[ind3] = n;
				ind3++;
				break;
			}
			case "a":{
				kurApvertimas[ind4] = n;
				ind4++;
				break;
			}
			
		}
			}
	

//sitas kodas sudaugina ir dalina, ir meta liekana(fmod()), ir nurodo tolesnei programos daliai, kur reikia sudeti, atimti, ir apversti;

//o dabar sudedame ir atimame: - si progr
for(int w = 0; w < ind2[].size(); w++){ //isimtinai sudetis
	ind = ind2[w] % 2;
	if(ind =1){
		b[kurSudetis[ind2]] = a[kurSudetis[ind2]]+b[kurSudetis[ind2]];
	} else {
		a[kurSudetis[ind2]] = a[kurSudetis[ind2]]+b[kurSudetis[ind2]];
	}
	
}

for(int w = 0; w < ind3[].size(); w++){ //isimtinai sudetis
	ind = ind3[w] % 2;
	if(ind =1){
		b[kurAtimtis[ind3]] = a[kurAtimtis[ind3]]-b[kurAtimtis[ind3]];
	} else {
		a[kurAtimtis[ind3]] = a[kurAtimtis[ind3]]-b[kurAtimtis[ind3]];
	}
	
}

for(int w = 0; w < ind2[].size(); w++){ //isimtinai sudetis

b[kurApvertimas[ind4]] = 1/b[kurSudetis[ind2]];

}

cout << "jusu skaicius yra" << a+b;

}


explanation - a is primary input, but also output component as it has even number
b is secondary input, also component, has odd number

The main task is to make sure the calculator prioritizes multiplication and division, also modulus. Also I would like you to add M+, M-, MC, MR, MS memory operations.

Cheers
The problem is not as trivial as it might seem at first blush. The solution is a really nifty analytical tool called 'grammar'. And no, I'm not criticizing your writing.

http://en.wikipedia.org/wiki/Parsing_expression_grammar

It'd take me a week to try and explain how to do this. Luckily, Bjarne Stroustrup has already done it. If possible, get your hands on a copy of "Programming Principles and Practice using C++" and check out chapters 6 - 7. He describes how to use grammars to solve the exact problem you're doing.
Topic archived. No new replies allowed.