+ 3
C++ signs as variable?
Is there a way to make a variable with the value of a sign like + or - ?
8 Antworten
+ 5
char a = '+';
if(a == '+')
cout << a << endl;
+ 5
Yes, but how can we compare the value when we can't even create a variable named + or - ?
int + = 5; // doesn't work
int a = 5; // works
if(a == +) // + is not variable
Tell me if I misunderstood you.
+ 4
Yes char variables are what you need.
+ 3
Valid variable name should begin with letter or underscore, followed by mixture of letters (uppercase or lowercase), underscore or number (in no distinct sequence). Symbolic character such as + or - are not qualified to form a variable name, nor to be part of a variable name. This is as I understand it.
+ 3
Ipang I mean as the value for the variable like how you would say int a = 2 or float b = 4. I’m wondering if there is something i could do to make the value a + or -
+ 3
Ipang It turns out I had to be using char
+ 2
Just in case someone doesn’t understand it would be something like “if (variable name == +) {cout << variable name}
+ 2
Yeah, now it's obvious : )
Well good to know you found what you're looking for 😁👍