Undeclared Identifier. How to fix?

So i don't know why i am getting undeclared identifier for yesnochoice in the while loop

int main()
do
{

int-
-
-

string -
-
-
string yesnochoice;
code code code
code code code

//TYPE (y/n) TO PLAY AGAIN
cout << "Do you want to play Again?" << endl << "(y/n)" << endl;
cin >> yesnochoice;

} while (yesnochoice = "y" || "Y" || "Yes" || "yes");

system("pause");
return 0;
}


Why am I getting this error, and how do I fix it?
Last edited on
Hey, please use code tags for all of your code - http://www.cplusplus.com/articles/jEywvCM9/

while (yesnochoice = "y" || "Y" || "Yes" || "yes");

That's not how it works.

1 -

= is an assignment operator.
== is a comparison operator.

You want to use == for obvious reasons.

2.

This is how you have to do it - (use ' ' instead of " " when it's a single char)

while(yesnochoice == 'y' || yesnochoice == 'Y' ||yesnochoice == "Yes" || yesnochoice == "yes" );
Thanks for the tips; however I still get the errors:

Error 1 error C2065: 'yesnochoice' : undeclared identifier

2 IntelliSense: identifier "yesnochoice" is undefined

Both talking about the "yesnochoice" inside the while loop.
1
2
3
4
5
6
7
8
cout << "Do you want to play Again?" << endl << "(y/n)" << endl;
			cin >> yesnochoice;

	} while (yesnochoice == 'y' || 'Y' || "Yes" || "yes");

	system("pause");
		return 0;
}
Did you ignore half my post? Look at the second half, I gave you the solution.

If you're still having errors after that, then you're gonna have to post your complete code =)
I started this yesterday, and its the first thing ive ever coded (besides web dev)
Ignore the to do list area. I know that its wrong just dont NEED that part quite yet.

 
//deleted but solved ;) 
Last edited on
This is a scope-based issue. Simply move your creation of yesnochoice to outside the loop.
1
2
3
4
5
int main()
{
        string yesnochoice; // create it here
	do 
	{


Also, if you're gonna use string - #include <string>

thanks for the help!
Topic archived. No new replies allowed.