If String = "something" [HELP]

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;
}





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int Random();
char want;

int main(){
cout << "Input \"Y\" to roll!" << endl;
cin >> want;
if(want=="y"); 
Random();
    
    
  system("PAUSE");   
  return 0;
}


int Random(){
    srand(time(0));
  for(int x =1; x<25;x++){
          cout << 1+(rand()%6) << endl;  
          }
          
  }
"y" is an array of 2 const char. Use single quotes if you want a char 'y'.
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.

Thanks Alot!
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.
Remove the semicolon on line 12.

change that system("PAUSE") function to cin.ignore().

cin.ignore() is not enough here because the new line char is still in the input buffer. Adding two calls to ignore will work better.
Ok, I see what you mean.
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
Topic archived. No new replies allowed.