Loop problem

Hello,
I am new to this website, and I am seeking for a little bit of help.
I am studying C++ and I am facing some sort of a problem with the loop function.

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
#include <iostream>
#include <string>

using namespace std;

int main()
{
	//Variables
	string choose; 
	int number1;
	int number2;

	//Output
	cout << "This program is written by: \n";
	cout << '\n';
	cout << "What do you want to do: Subtract, Add, Multiply, Divide?\n";
	cout << "I want to: ";
	cin >> choose;
	cout << '\n';

//loop
	while( choose != "Add" || choose != "Subtract" || choose != "Multiply" || choose != "Divide" )
	{
		cout << '\n';
		cout << "Input not recognized, try again\n";
		cout << "What do you want to do: Subtract, Add, Multiply, Divide?\n";
		cout << "I want to: ";
		cin >> choose;
	}

	//If the user chooses to subtract
	if(choose == "Subtract")
	{
		cout << "It seems you have chosen to Subtract, Choose your first number: ";
		cin >> number1;
		cout << "Now choose your second number: ";
		cin >> number2;
	}

	cin.get();
}


So, I tried the loop, and if I don't input one of strings "Add, Subtract, Multiply or Divide" it loops again (So far everything is fine), so I have to tried to input the right string "Subtract", but instead of displaying the if function, it displays the loop function once again, instead of the if function.

Here's an image so you can understand:
http://www.uploadffs.nl/images/2012/12/25/jPitm.png

Thanks for your support :)!
Hope you can help me.
Well, your condition is "if choose is not equal to "Add" or if choose is not equal to "Subtract"..."
choose can't equal all of those at the same time, so the condition is always true.
Logical and would be the right operator to use here.
Last edited on
I can almost get you, I can't understand what operator should I use. Because I've seen most passwords check with the operator "!="
Logical and is &&. || is logical or. != is "not equal".
http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
Thanks, I fixed it =)
Topic archived. No new replies allowed.