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,
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 came up with a cool phrase to put down here, but i forgot it...
I thought it was strcmpi()
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
stricmp() and strcmpi() both work.
I believe neither is an ANSI standard function?
Someone correct me if I'm wrong.