ok I've done a program with switch code, the thing is that I want to be able to let the user type "YES" or "NO" in one of the options so that the program should re-start or whatever.. do you know what i mean?
Thanks,
Printable View
ok I've done a program with switch code, the thing is that I want to be able to let the user type "YES" or "NO" in one of the options so that the program should re-start or whatever.. do you know what i mean?
Thanks,
Get the command as a string
char stringname[4];
cin >> stringname;
then compare it (case-sensitive)Code:if (srcmp(stringname,"YES")==0) {
cout << "stringname is YES" << endl;
}
>if (srcmp(stringname,"YES")==0) {
Small typo:
if (strcmp(stringname,"YES")==0) {
Or you can use C++ style strings:
Code:#include <string>
using namespace std;
int main(void)
{
string stringname;
cin >> stringname;
if (stringname == "YES")
cout << "stringname is YES" << endl;
return 0;
}
you can use stricmp() for case insensitive comparisons.
I thought it was strcmpi()
stricmp() and strcmpi() both work.
I believe neither is an ANSI standard function?
Someone correct me if I'm wrong.