Ask coding questions

← Back to all posts
C++ Programm Calculator Squaring
FallingNever

I wrote a calculator programm in C++, which is just able to square a number.
My question is how can I fix the code. Because when you compile this code and enter a floating point number, it outputs also something else. Down below is the code from my repl.

Answered by Highwayman [earned 5 cycles]
View Answer
Voters
FallingNever
Comments
hotnewtop
Highwayman

you are unconditionally parsing the number as an int and outputting the square of that at the end.(lines 38 to 40)

I suggest properly formatting your code, because right now it's messing with how easily one can follow the logic. Once you do that, it should be pretty easy to see the error.

FallingNever

@Highwayman Thanks! It is working!

Highwayman