+ 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.
7 Answers
+ 1
You can declare it as a character:
char = z;
cin >> z;
if (z = '+') {
cout << x + y;
}
etc.
0
What I mean is setting a variable to the actual symbols + and -, not positive and negative numbers.
0
I'm not quite sure about that but try this: x = "-" or you can do this x = "+"
0
What should you declare the variable as though?
0
Are you trying to make your code look like a calculator or to justvhave the user input an equation?
0
I'd like the user to input an equation like "1 + 1"
0
u can store it as a character array (string) and then parse the string for ascii + or - ...