+ 3

Is there any way to set a variable to a symbol like + or -?

I'm trying to make a calculator and I want to make it so you just type an equation. [EDIT] - What I mean is the actual symbols. Not positive and negative numbers.

21st Aug 2017, 7:07 PM
The Muse
The Muse - avatar
7 Answers
+ 1
You can declare it as a character: char = z; cin >> z; if (z = '+') { cout << x + y; } etc.
26th Aug 2017, 8:08 AM
ReimarPB
ReimarPB - avatar
0
What I mean is setting a variable to the actual symbols + and -, not positive and negative numbers.
21st Aug 2017, 7:27 PM
The Muse
The Muse - avatar
0
I'm not quite sure about that but try this: x = "-" or you can do this x = "+"
21st Aug 2017, 7:31 PM
Alex
0
What should you declare the variable as though?
21st Aug 2017, 7:35 PM
The Muse
The Muse - avatar
0
Are you trying to make your code look like a calculator or to justvhave the user input an equation?
21st Aug 2017, 7:36 PM
Alex
0
I'd like the user to input an equation like "1 + 1"
21st Aug 2017, 10:54 PM
The Muse
The Muse - avatar
0
u can store it as a character array (string) and then parse the string for ascii + or - ...
22nd Aug 2017, 3:59 PM
Hemant Kumar
Hemant Kumar - avatar