I am new to programming and this is my second assignment. It is supposed to accept input from user until they enter the |
to exit the program. What have I done wrong?
int main()
int i = 0;
char a = 0;
while ( a != "|" ){ //has also told me this is an
// invalid operator
int numeric;
cout << "Give character: ";
cin >> a ;
cout << "Its ascii value is: " << (int) a << endl;
++i;
}
}
Here is the error:
2 IntelliSense: operand types are incompatible ("char" and "const char *")
Don't use "|"
. Put '|'
instead. You want to compare a char
to a char
, NOT compare a char
to a char*
.
You shall use while ( a != '|' )
instead
'|'
is a character and "|"
is a string which has only 1 character
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.