Validating a string???
Good Morning All,
I am sure this is something simple but I'd like some help. In the example code below I would like to evaluate a string for a response or group of responses using any of the loop functions.
Any help would be greatly appreciated.
Keith
#include <stdio.h>
#include <iostream.h>
using namespace std;
string userName;
string gameOn;
int main()
{
cout << "What is your name? \n";
cin >> userName;
cout << "Nice to meet you " << userName << "!\n\n";
cout << "Would you like to play a game?: \n";
cin >> gameOn;
if ????gameOn???? //an answer of "Yes", "yes", "Y" or "y" is the criteria
{
cout << "Great, lets begin!\n\n";
}
return 0;
}


Hi! docklab try this, hope it works for you
#include <stdio.h>
#include <iostream.h>
using namespace std;
string userName;
string gameOn;
int main()
{
cout << "What is your name? \n";
cin >> userName;
cout << "Nice to meet you " << userName << "!\n\n";
cout << "Would you like to play a game?: \n";
cin >> gameOn;
if ((gameOn=="Yes")||(gameOn=="yes")||(gameOn=="Y")||(gameOn=="y"))
{
cout << "Great, lets begin!\n\n";
}
return 0;
}
Try this on bOtskOOl online c/c++ compiler
Note:- This post has been edited by aamiraarfi at Tue, 03/09/2010 - 14:22.
It is always so simple once you see it. Thank you my friend!!!
Doc
Happy coding
Im back. I am just playing around and trying to learn C++ but I'm now stuck with a pointer problem.
Below is a continuation of the previous code, and while it compiles fine I get this error with any input:
////////////////////////////////////////////
/////////////////////////////////////////////
The full sample code is below. If you can help me understand this error, I would greatly appreciate it.
Hi dockab,
Your program is working fine in bOtskOOl Online Compiler. Check the screenshots below -
Correct Sashwat, It does indeed work with in this compiler,
With in Xcode however, the code compiles without error but fails to run and results in the pointer error.