Binary Operations

Code:
#include <iostream>
#include <string>
using namespace std;

void process(string operator, int first_bit, int second_bit) {
if (operator == "AND") {
if (first_bit == 0 || second_bit == 0) return 0;
return 1;
}
else {
if (first_bit == 1 || second_bit == 1) return 1;
return 0;
}
}

int main() {
int type, n, first_bit, second_bit;
string operator;

cin >> type;
if (type == 1) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> operator >> first_bit >> second_bit;
cout << process(operator, first_bit, second_bit) << endl;
}
}
else if (type == 2) {
while (true) {
cin >> operator;
if (operator == "0") break;
cin >> first_bit >> second_bit;
cout << process(operator, first_bit, second_bit) << endl;
}
}
else {
while (true) {
cin >> operator;
if (cin.eof()) break;
cin >> first_bit >> second_bit;
cout << process(operator, first_bit, second_bit) << endl;
}
}
return 0;
}

Need help with the error - declaration of operator as non function?
This programs seeks to output either 1 or 0 for inputs regarding operations "AND" or "OR" only and seeks the user input for the type he wants. At most 100 operations need to be performed and there is no need for exceptions testing such as user deciding to enter 0 or more than 100 inputs.

Type 1: Read n lines.
Type 2: Read until special character, which only needs to be considered as "0".
Type 3: Read until eof.

For example, for type 1:
1
2
AND 0 1
OR 1 1

Output:
0
1

Type 2:
2
AND 1 1
OR 0 0
0

Output:
1
0

Type 3:
3
OR 0 1
AND 1 0
OR 1 1

Output:
1
0
1

Compilation problem points to my function 'process'.
Last edited on
operator is a reserved word, you cannot give a variable this name.
Last edited on
I see. Thanks for your help.
Topic archived. No new replies allowed.