I receive an error message when creating an if statement asking for a specific string of text. Can someone please help me out. Sorry for the stupid question.
Error Messages:
In function `int main()':
ISO C++ forbids comparison between pointer and integer
1 2 3 4 5 6 7 8 9 10 11 12 13
int Random();
char want;
int main(){
cout << "Input \"Y\" to roll!" << endl;
cin >> want;
if(want=="y");
Random();
system("PAUSE");
return 0;
}
When I change "y" to 'y' , I am able too enter anything and the if will still run.
Can you make your revisions too what I have already. In case there's something I missed.
Just a tip unrelated to your post, change that system("PAUSE") function to cin.ignore(). Looks much cleaner. System functions are frowned upon because I believe they pause every function of the computer, might be mistaken though.
I believe a call to cin.clear() will clear out the buffer. So a call to that then a call to cin.ignore() would do it. System("PAUSE") is just inefficient and flawed security wise.
ResidentBiscuit, cin.clear() just clears the error flags. It doesn't change the input buffer. I understand that people continue to use system("pause"). It just works and is not affected by the state of the input buffer. As a beginner efficiency and security is not top priority.
I find it amusing that it's only windows users that have this problem :P