How do you read arithmetic symbols using char | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you read arithmetic symbols using char

I'm trying to program a simple calculator

4th Jun 2017, 10:47 PM
Theophilus Mashego
Theophilus Mashego - avatar
5 Answers
+ 3
read the whole input as a string perhaps? if you are wanting the user to input a whole expression that is how I would approach it (i.e user input: 6 * 6 =)
4th Jun 2017, 10:50 PM
jay
jay - avatar
+ 3
you could seperate the inputs and have the program store the symbol seperate to the numbers. i.e ask user for number. store as double/float ask user for symbol. store as char/string ask user for another number: store as double/ float. then you could use if/else statements to select the correct symbol and perform the calculation on the numbers
4th Jun 2017, 10:55 PM
jay
jay - avatar
+ 1
I see that makes sense but what if I want to use if statements?
4th Jun 2017, 10:51 PM
Theophilus Mashego
Theophilus Mashego - avatar
+ 1
yeah I did but my Problem is that you see when getting data from the user using the scanner I don't know what to use to assign the data to symbol/operator if wanted an integer from the user I would say num1 = console.nextInt() what do I write for char?
4th Jun 2017, 11:02 PM
Theophilus Mashego
Theophilus Mashego - avatar