Author Topic: Problem with scanning a double type  (Read 7203 times)

Offline Oranm

  • Single posting newcomer
  • *
  • Posts: 3
Problem with scanning a double type
« on: October 15, 2017, 03:33:03 pm »
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;
}

Any help would be much appreciated!
Best regards,
Oran
« Last Edit: October 15, 2017, 03:43:58 pm by Oranm »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Problem with scanning a double type
« Reply #1 on: October 15, 2017, 03:52:26 pm »
Are you sure your program is rebuild? Have you tried to change
Code
printf("%lf",x);
to
Code
printf("My number is:%lf",0.22);
And look if the output is correct
Code
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

Offline Oranm

  • Single posting newcomer
  • *
  • Posts: 3
Re: Problem with scanning a double type
« Reply #2 on: October 15, 2017, 04:05:56 pm »
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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Problem with scanning a double type
« Reply #3 on: October 15, 2017, 08:09:24 pm »
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);

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.

« Last Edit: October 15, 2017, 08:12:24 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org