Consider using a string if possible , reason is if multiple characters are being read into char then most of them will be leftover in your input buffer. Btw exactly what warning did you receive.
In you code the error sprout from comparing a char to a string like literal if((ch=='++')||(var=='++'))
The above line is in error because a char variable can only hold a single char and a char literal can not hold more than one chat ie. '++'/*invalid char litetal*/ '+','+'/*two valid char litetals */
'++' //means you want to use either an array of chars i.e. const char* or std::string
#include<iostream>
#include<string> // prefer std::string to const char*
usingnamespace std;
int main()
{
int n,total=0;
string ch,var, incr ("++"), decr ("-");
/// prompt the user that you expect some inputs
cin>>n;
for(int a=1;a<=n;a++)
{
cin>>ch>>var;
if((ch==incr)||(var==incr))
{
total++;
}
elseif((ch==decr)||(var==decr))
{
total--;
}
}
cout<<total;
return 0;
}
you can read more about strings here
http://www.cplusplus.com/reference/string/string/
http://en.cppreference.com/w/cpp/string
http://www.cprogramming.com/tutorial/string.html
Multicharacter literals (something like '++') are not characters. They are integers. Implementation defined integers to boot, so you cannot really say anything aside that it is some integer. It is C leftover, and almost always used incidentally and is undesireable and sign of mistake, that is why it emits a warning. Just like trigraphs.
It is simple: you cannot store several characters in data type serving to store single characters.
Multicharacter literals (something like '++') are not characters. They are integers.Implementation defined integers to boot,
that av not heard about wow, so @Miinippa are they of any use or are they applicable in a program and what would they be used for , coz it's like they dark syde outweigh their advantages, how are they integers haha ?? Thank you..
Like trigraphs they are almost useless and superseded by other language features.
Sometimes you might use them as internal constants (poor man enumerations):
1 2 3 4 5
int code = 'succ';
if (something)
code = 'err';
//...
if(code = 'err')
Well that was amazing though i dint get a thing right there hehe , btw I could see their typeid ... maybe one of these day i'll check 'em out and (trigraphs too) Btw just for adventure hehe .
Thanks @Miinipaa , th was gr8