News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Problem with scanning a double type

Started by Oranm, October 15, 2017, 03:33:03 PM

Previous topic - Next topic

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:
#include <stdio.h>

int main(){
    double x;
    scanf("%lf",&x);
    printf("%lf",x);
    return 0;
}


Any help would be much appreciated!
Best regards,
Oran

BlueHazzard

Are you sure your program is rebuild? Have you tried to change
printf("%lf",x);
to

printf("My number is:%lf",0.22);

And look if the output is correct
My number is:0.22

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

#3
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.

printf("My number is:%f",0.22);

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.

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]