How can i declare + | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How can i declare +

When i make: if ( g = + ) it makes error Can i somehow declare +

6th Jan 2019, 2:50 PM
Denis Ć abata
Denis Ć abata - avatar
4 Answers
+ 11
Try if(g=='+') { ...... } Now I may work as in the if condition, you should use ==(comparison operator) and plus sign (+) is evaluated as a character so it should be surrounded by single quotes (' '). Hope this helps.
6th Jan 2019, 2:58 PM
Nova
Nova - avatar
+ 5
Just a question, are you testing if variable g is equal to character + ? If yes, write : if(g=='+') { }
6th Jan 2019, 2:54 PM
Théophile
Théophile - avatar
+ 3
if (g = +) is thinking the + sign is a Operater doing something, And = is the assignment Operater. == Is telling if it is Equal to that Value; Change it into a String(Text) and change the = to ==: if(g == “+”) then your code is okay again!!
7th Jan 2019, 6:08 AM
Potato Hacker
Potato Hacker - avatar
+ 2
Thanks guys :*
7th Jan 2019, 6:06 PM
Denis Ć abata
Denis Ć abata - avatar