-
November 11th, 2014, 10:02 AM
#1
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
-
November 11th, 2014, 10:19 AM
#2
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
-
November 11th, 2014, 10:36 AM
#3
Re: problem with 'long double' datatype in c++
main() should be defined as returning a type int
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 11th, 2014, 10:39 AM
#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.
-
November 11th, 2014, 10:42 AM
#5
Re: problem with 'long double' datatype in c++
@2kaud
I've tried with 'int main()'. but again got the same result.
-
November 11th, 2014, 11:20 AM
#6
Re: problem with 'long double' datatype in c++
Victor Nijegorodov
-
November 11th, 2014, 12:44 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|