dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: problem with 'long double' datatype in c++

  1. #1
    Join Date
    Nov 2014
    Posts
    4

    problem with 'long double' datatype in c++

    my code:

    #include<cstdio>
    #include<iostream>

    using namespace std;

    main()
    {
    long double j;
    scanf("%Lf", &j);
    cout<< j;
    return 0;
    }

    If I give any number as input, the output is always 0. why? where's the problem ? plz help

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,623

    Re: problem with 'long double' datatype in c++

    What compiler are you using?
    Does this code compile?
    What if you change the long double to double?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,036

    Re: problem with 'long double' datatype in c++

    main() should be defined as returning a type int
    Code:
    int main()
    apart from this, it compiles and runs as c++ as expected using VS2013.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.5.1)

  4. #4
    Join Date
    Nov 2014
    Posts
    4

    Re: problem with 'long double' datatype in c++

    thanks for your rreply.

    I'm using code::blocks IDE. (version 13.12)

    Yes, this code compiles and runs.

    It works well if i use 'double' instead of 'long double'. But I've to store a relatively large number.

  5. #5
    Join Date
    Nov 2014
    Posts
    4

    Re: problem with 'long double' datatype in c++

    @2kaud

    I've tried with 'int main()'. but again got the same result.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,623

  7. #7
    Join Date
    Nov 2014
    Posts
    4

    Re: problem with 'long double' datatype in c++

    thanks.
    i was right. the problem wasn't in my code, rather in codeblocks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)