Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Floating point

ABDUL HAYEEABDUL HAYEE Posts: 81Member
Dear sir,
I am a student , studying at home.
I have just begun C++ reference book by Sietel and dietel .

In coding an exercise , i am facing difficulty in getting the answer in decimal figures , although i am using data type " float ". code has been furtheer simplified just to indicate the problem.
The book tells to use an unfamiliar function

static_cast (total) / 3 ;
cout << " Average is " << setprecision (4)
<< setioflage(ios::fixed | ios::showpoint)
<< avg << end1 ;

Obviously , at this stage i do not know from where and how to get these data types , and their usage.

My Questios are :
1. Is there any other data type , that might give decimal answer?
2. where can I get above refered functions , and to know their
usage .
3. end1 --- command is not being supported by the Dev C++
version 4.9.9.2 ........... what is the alternative.

Thanking you .
ah.

Comments

  • VilanyeVilanye Posts: 684Member
    :
    : My Questios are :
    : 1. Is there any other data type , that might give decimal answer?
    [blue]Floating point data types are float and double. Their sizes are compiler and platform dependant. Generally, double is larger the float, but they can be the same, I think.[/blue]
    : 2. where can I get above refered functions , and to know their
    : usage .
    [blue] setprecision is part of ios is make sure the are included. You didn't post enough code. An elegant reference library seems to be lacking with the C++ language, I also found googling for a specific function is the way to go. Here is one, it is from microsoft, but the page claim it is the standard library: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang98/HTML/INDEX_Table_of_Contents.asp. Here is a pdf that looks complete but I didn't look through it http://www-1.ibm.com/support/docview.wss?uid=swg27002104&aid=1
    [/blue]
    : 3. end1 --- command is not being supported by the Dev C++
    : version 4.9.9.2 ........... what is the alternative.
    [blue]It is hard to tell but the l in endl is not a one, it is a lower case L. That could be your problem. endl is part of the standard, so it should be supported, on any compiler claiming standards compliance. Again, you didn't post enough code. cout evidently works, as does setprecision, so there should be a line towards the top: using std::cout, make sure there is a line that says "using std::endl", without the quotes. Alternatively you can skip the using statements, but that means you need to type std:: alot. If for some reason endl does not work after this, you need a up to date compiler, or not have the ability to use it. "
    " is similar to endl but is lacking one important ability,
    does not flush the buffer. [/blue]
    :
    : Thanking you .
    : ah.
    :
Sign In or Register to comment.