Skip to content
Sign upLog in
← Back to Community

C++ adding numbers??!!!

Profile icon
Baconman321

Ok, this is weird, and I am more of looking for an answer as to why this is happening because I am VERY curious on how this could possibly work. If you compile the program, choose add as your operator, and enter a as your digit, it outputs something like 2.07427e-317. What is happening?!

Answered by mwilki7 [earned 5 cycles]
View Answer
Voters
Profile icon
s74646686
Profile icon
BB07-GARCIAGARC
Profile icon
Baconman321
Comments
hotnewtop
Profile icon
mwilki7

that just means it's a really small number

Profile icon
Baconman321

@mwilki7
Ok, but why would c++ add letters?

Profile icon
mwilki7

@Baconman321
my guess is the print library is doing that
e is short for exponent and it's giving you the number in scientific notation
for instance:
6.52942e-08
is
image

If you want it to stop doing that, check out:
https://stackoverflow.com/questions/6301547/turn-off-scientific-notation-on-float

Profile icon
Baconman321

@mwilki7
What e?

Profile icon
mwilki7

@Baconman321

image

Profile icon
Baconman321

@mwilki7
Ok, but why would c++ take something like a letter and try to add it. Is it because of the letter being assigned a number or something?

Profile icon
mwilki7

@Baconman321

it's still a number, the std library that implemented cout is the problem

you can configure it so it prints it out differently

Profile icon
Baconman321