0
hey guys, im new here and i really need your help with a c++ code :)
so, im making a simple calculator code (im using code blocks, thats why im not including the code here), and almost everything works fine, except when the program makes a sum for example, the result is some crazy number.. i dont know what is happening. can u guys help me?
5 Respostas
+ 5
Sounds like garbage values due to uninitialised sum variable. Without the code, we can't really help you. The best course of action would be to show your code.
Did you do
int sum;
instead of
int sum = 0;
?
+ 2
Mmm, it would still help us to come to a conclusion with what's done wrong if you can attach the code. You can copy and paste it directly here as a post, if you see it fit.
+ 1
Try double instead of float.
Also try:
double sum = 0.0;
sum = (double) value1 + (double) value2;
Also check this (from Oracle, but relevant): https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
0
i did float sum = value1 + value2 (thanks for answering!)
0
with the ; at the end, i forgot to put it above