PLEASE HELP STUPID ISSUE HERE
hey im having an annoyin dev c++ issue. here is my extremely basic code, dw bout context:
Code:
#include <iostream>
#include <cmath>
#include <windows.h>
char a[100];
int main(){
using namespace std;
cin >> a;
if (a == 'si')
{
cout << a <<" is 'Yes'"<<endl;
}
else if (a == 'hh'){
cout <<"baf"<<endl;
}
else if (a == 'hfs'){
cout <<"fgy"<<endl;
}
else
{
cout <<"fua"<<endl;
}
system ("pause");
return 0;
}
im trying to get it to output the char but it wont run.
when my code was like this:
without the value for the char, it ran but only printed out the first letter, because its a char. but when i put it like this:
i get the error:
ISO C++ forbids comparison between pointer and integer
please help.
Hey, i found your problem.
At all the if( a == 'stuff') you are using 'stuff', when you should be suing "stuff" since single quotations are only for single characters. While double quotations are for strings.
sherif, just try using a string. Its easier for this purpose and will cause you less trouble
strings never work 4 me wen i try to use cin >>
its only eva worked once and even copying the working source code does nothing
That is incorrect, when you compare a[1] and 'si' it is wrong. First off, a[i] is actually a character not a string, 'si' is not a character. Using ' ' is only for characters, " " for strings. Therefore when you compare a[1] and 'si' you are comparing the second element in the string with the character 's' since 'si' can only hold one character.
just tested and it works thanks tonnes