User forums > Using Code::Blocks
Problem with scanning a double type
(1/1)
Oranm:
Hello,
I am using Code::Blocks 10.05.
Recently I tried writing a program which uses a double type.
The return wasn't as expected so I began debugging.
Finally I found out that I have problem with scanning a double type, even tried it in a different project to isolate the case, still doesn't work.
No matter what is the input, the print is always 0.0000...
Example code:
--- Code: ---#include <stdio.h>
int main(){
double x;
scanf("%lf",&x);
printf("%lf",x);
return 0;
}
--- End code ---
Any help would be much appreciated!
Best regards,
Oran
BlueHazzard:
Are you sure your program is rebuild? Have you tried to change
--- Code: ---printf("%lf",x);
--- End code ---
to
--- Code: ---printf("My number is:%lf",0.22);
--- End code ---
And look if the output is correct
--- Code: ---My number is:0.22
--- End code ---
If your program is rebuild correctly and you still get the wrong number:
Your question has absolutely nothing to do with codeblocks. This question is C or Compiler related and this forum does not provide any support for either.
If your program does not get rebuild and you does not get the expected output:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
Not related to your question: Codeblocks 10.05 is soooooooooo old. I would update
[edit:] are you sure you enter the number correctly with the correct coma separator for your language/terminal
Oranm:
Hey BlueHazzard, thanks for your reply!
I did try the printf line you suggested, still getting 0.0000.
The reason I use 10.05 is because this is what my university demands, we also code with C89 format instead of C99....
Anyway, I did try this on a different empty project and it seems to work as expected (like it did before), I guess I can conclude the issue has something to do with the built-in wizard that is installed by my university.
If you have any other conclusions I'd be glad to know :)
Thanks for your time, Oran
stahta01:
You need to find an C/C++ support website for your compiler.
Find out all the information about your compiler you are using, before posting on it.
--- Code: ---printf("My number is:%f",0.22);
--- End code ---
You compiler likely does NOT support "lf"; in the printf statements this is common with old compilers!
I suggest signing up for help on https://cboard.cprogramming.com/forum.php it can take a few days for the signup to be approved.
Tim S.
Navigation
[0] Message Index
Go to full version