Menu

Precision & Fixed commands

2002-10-14
2012-09-26
  • Nobody/Anonymous

    I am trying to get a value output to two decimal places using code that works in MS Visual C++:
    cout << fixed;
    cout.precision(2);
    but in bloodshed I am getting errors that "Fixed" is undelcared.  Do I need to include another libary other then cmath?  In MS C++ need to add the line "using namespace std;" after my #includes, but bloodshed dosen't seem to reconize that line.
    Thanks.

     
    • Nobody/Anonymous

      Here is something i put together that uses what you asked about.
      Could be better,but i did it for demo not great style...

      #include <iostream>
      #include <iomanip>
      #include <stdlib.h>
         
      using namespace std;

      int main()
         {
      cout.setf(ios::fixed); // " "                    
      cout.precision(2) ; // both affect all below
         
      double salePrice = 0;
      double discnt = 0;
      double oPFactor = 1;
         
                
      cout <<"Test Program "<< "\n";
      cout << " Enter sale price and the Discount% as: .10 = 10%" << "\n \n";
      cout << " Enter the salePrice " << "\n \n";
      cout << ": ";
      cin >> salePrice;         
                        
      cout << "\n";
                                         
      cout << " Enter the Discount " << "\n \n";
      cout << ": ";
      cin >> discnt;   
      cout << "\n";
              
      double  oPrice = (salePrice * (oPFactor/(oPFactor-discnt))); 
              
        cout << "The Price befoe the Discount was: " 
        << setw(14)<< oPrice << "\n";
                 
      system("PAUSE");
      return 0;
      }

      j@ck_

       
    • Nobody/Anonymous

      Great style or not it works perfect, Thanks.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.