Comparing C++ input with array values
- by Security_Gate
Hey everyone,
Over the last couple months I've still been slowly but surely trudging through C++, and I've run into a snag that I've been meaning to figure out. I've tried asking/reading/searching, but I could never find an appropriate answer. Maybe it is simply because the question is sort of difficult to ask.
What I'm trying to do is at the end of my program, have the end sequence compare the input value with values within an Array. Do I have to loop a comparison sequence? Is there an easier way around this?
#include <iostream>
#include <string>
using namespace std;
int main () {
string YesAnswers[5] = {"Y", "YES", "yes" "y"};
string Name;
string YN;
do {
cout << "Enter your name: ";
getline(cin, Name);
cout << "Your name is "<< Name;
cout <<"\nIs this correct? Y\N: ";
cin >> YN;
} while(YN == YesAnswers);
system("Pause");
return 0;
}