0

I can't use Point (Float) Numbers in my calculator (C++)

Problem is that I'm working on Updating my 11 months old Calculator written in C++ and It's mostly all done. I can divide smaller numbers bigger (2 / 4 = 0.5). One problem that occured is i can't + two point numbers (0.5 + 0.5 results in Error) or - two point numbers or * two points numbers so I ask here for some help. Thanks in advance Script: https://code.sololearn.com/cyqTln6peslH/?ref=app

15th Apr 2018, 9:27 AM
Mikuláš Suchanovský
Mikuláš Suchanovský - avatar
4 odpowiedzi
+ 4
You get the error because you accept 0.5 as integer, in which case only the zero will be assigned into variable "a", afterwards you have "garbage" value in the input stream, which makes your code assign the digit separator (.) as your operator "op" here on, your switch statement sees that user had typed an invalid operator and refuse to process the data (show error message).
15th Apr 2018, 10:48 AM
Ipang
+ 1
Thanks a lot! Both of you. Thanks Mohamed for fixing it and Ipang for moe info about this stuff.
15th Apr 2018, 10:54 AM
Mikuláš Suchanovský
Mikuláš Suchanovský - avatar
0
Can you tell me more please? At least little insight how to do it.
15th Apr 2018, 10:15 AM
Mikuláš Suchanovský
Mikuláš Suchanovský - avatar
0
Thanks fot help! Gonna check it and give some info. Also is there way to convert int to float?
15th Apr 2018, 10:46 AM
Mikuláš Suchanovský
Mikuláš Suchanovský - avatar