how to set decimal places Borland C++ 3.0 compiler???

This is a discussion on how to set decimal places Borland C++ 3.0 compiler??? within the C++ Programming forums, part of the General Programming Boards category; Note: this is is just a repeated question found under C Programming: I am very sorry, please delete the message ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    30

    how to set decimal places Borland C++ 3.0 compiler???

    Note: this is is just a repeated question found under C Programming: I am very sorry, please delete the message found in C Programming.

    Hello guys,

    I am finding hard, what really the function to set the decimal places in two places using the compiler Borland C++ 3.0. I know already setprecission function that is found in the latest compiler such as borland c++ 4.5 or 5.5. But in Borland C++ 3.0 there is no function as setprecission found in the iomanip.h library.

    I am using Borland C++ 3.0. Hope you can help me this thing.


    Example:



    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <iomanip.h>
    
    int main()
    
    {
         float a, b, c, average;
    
         clrscr();
         while (a <= 3)
              {
                   cout <<"Enter number: ";
                   cin >> b;
                   c = c + b;
                   a++;
       
              }
          
          average = c / a;
          cout << average;
          
          getch();
          return 0;  
          
    
    }
    I want to display the output into two decimal places, I know the solution using setprecission such as:



    Code:
     cout << average << setprecission(2);
    But the problem is I could not find setprecission in Borland C++ 3.0 compiler. Thanks in advance...

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    thatd be because it's spelled 'setprecision'
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    30
    Hehehe, I am very sorry for the spelling...

    Yap, when I compiled the program and run it, it gives me an error... When I browse the help of the iomanip.h library, there is no setprecision under Borland C++ 3.0... The only found in the help is the setp, setw, etc... But there is no setprecision there. I am using a DOS Borland C++.

    Sorry for the ignorance..... Thanks again...

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well... first I would suggest you get an up-to-date compiler... dev-c++ is a good free (as in free beer) IDE that uses the MingW port of GCC, and follows standards pretty well...

    by "DOS Borland" I'm assuming you mean "command line" borland, and you're not actually running DOS
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    30
    I got the solution, I have found it in the www.cplusplus.com;


    Code:
    cout << average << '%.2f';

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    oh yuck... I didn't even know that was possible... but... yuck... to like the 20th degree...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    cout << average << '%.2f';
    Does that actually work? I seriously doubt it because:

    You can't have a string like '%.2f'; you need to use double quotes, like "%.2f".

    Because of the way cout works, the ostream object that prints average has no knowlege of what follows it. The above code is the same as
    Code:
    cout.operator<<(average).operator<<('%.2f');
    There's no way that it could know about the %.2f. %f is a format specifier from printf. It doesn't have anything to do with cout.

    When you compile that code, you'll get an error. When you use double quotes and then re-compile it, you'll get output like this:
    Code:
    123.6%.2f
    if average is 123.6.

    [edit] As for your problem, you might want to try printf(), which is an old C function, but at least it will work (and it uses %.2f, unlike cout). [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Does that actually work? I seriously doubt it because:
    I doubt it even compiles.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Did you read farther? It can't compile, unless the OP copied in incorrectly and it was meant to be double quotes, in which case it still wouldn't work because there's no way the first ostream could know about the second.

    [edit] I suspect the OP saw in a (C) thread something like "To output only two decimal places, use %.2f", and then tried to do just that. [/edit]
    Last edited by dwks; 08-31-2006 at 09:41 AM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I would suggest setprecision, but if your compiler is so old it doesn't have that, you might want to use printf().
    Code:
    #include <cstdio>  /* or <stdio.h> if your compiler doesn't have <cstdio> */
    printf("%.2f", average);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by dwks
    Did you read farther? It can't compile, unless the OP copied in incorrectly and it was meant to be double quotes, in which case it still wouldn't work because there's no way the first ostream could know about the second.

    [edit] I suspect the OP saw in a (C) thread something like "To output only two decimal places, use %.2f", and then tried to do just that. [/edit]
    Well admittedly I missed the line where you said:
    >You can't have a string like '%.2f'; you need to use double quotes, like "%.2f".

    I interpreted:
    >Does that actually work?
    to mean not a compile error, but undesired output.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  2. how to set up borland compiler from this site
    By dawiz66 in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 04:45 PM
  3. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 05:05 PM
  4. How do I set up Borland's C++ Free compiler
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 11-03-2001, 10:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21