OR operator

How would you use an OR operator, I tried to use it |
V

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
  #include <iostream> 
#include <Windows.h> 
#include <conio.h> 
#include <string> 

using namespace std; //No need to explain...

void Main()
{
	int num1 = 0, num2 = 0, Continue = 1;
	string Operator;

	while(Continue == 1)
	{
		cout << "Hello, and thank you for choosing Awesome Calculator v1.0" << endl;
		cout << "Please enter an operation such as +, -, /, or *" << endl << endl;
		getline(cin, Operator);
		if(Operator != (+ || - || / || *))
{
cout << "That is not a mathematical operator, please input a mathematical operator:  "
}


	}

}



The || function is not working as I thought it would. I want the if statement to occur if the string "Operator" is not equal to + - / *

This is NOT homework, I like to use C++ to make simple programs for self amusement.
it says || expected an expression
You need to split up that statement and put your actual operators as strings:
if(Operator != (+ || - || / || *))
Should be:
if (Operator != "+" || Operator != "-" || Operator != "/" || Operator != "*")

However, if we look at this logically now, we can see that if it fits any one of those conditions, the others will be true and we will always enter the loop. Therefore we actually need to use the && symbol:

if (Operator != "+" && Operator != "-" && Operator != "/" && Operator != "*")
Last edited on
You can't group conditions that way, also you don't have " " around the signs, so it expects an operands. Change line 18 to
 
if (Operator != "+" && Operator != "-" && Operator != "/" && Operator != "*")


If you want to use ||s, then the required code is:

 
if (!(Operator=="+" || Operator=="-" || Operator=="/" || Operator=="*"))
Last edited on
thx guys
Instead of

void Main()

you hace to write

int main()
Topic archived. No new replies allowed.