Menu

HELP: using 'fixed'

2003-02-09
2012-09-26
  • Nobody/Anonymous

    I tried a simple program, but received a compilation error regarding using 'fixed':

    THE PROGRAM:

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;
    using std::fixed;

    #include <iomanip>

    using std::setprecision;

    int main()
    {
        double miles,gallons;
        double miles_tot=0;
        double gallons_tot=0;

        cout << fixed << setprecision(2);

             
        cout<<"enter the gallons used (-1 to end): ";
        cin >> gallons;
       

        while (gallons >= 0)
        {
            cout<<"Enter the miles driven: ";
            cin >> miles;
       
            cout << "The miles / gallon for this tank was: "<< miles/gallons << endl << "\n";
            miles_tot=miles_tot+miles;
            gallons_tot=gallons_tot+gallons;
           
            cout<<"enter the gallons used (-1 to end): ";
            cin >> gallons;
         }
       
        if (gallons_tot != 0)
            cout << "The overall average miles/gallon was: " << miles_tot/gallons_tot;
       
        cin.get();
        cin.get();
        return 0;
    }

    THE COMPILER:

    D:\Dev-Cpp\Users\Yoav\2.16.cpp: In function `int main()':
    D:\Dev-Cpp\Users\Yoav\2.16.cpp:19: `fixed' undeclared (first use this function)
    D:\Dev-Cpp\Users\Yoav\2.16.cpp:19: (Each undeclared identifier is reported only once
    D:\Dev-Cpp\Users\Yoav\2.16.cpp:19: for each function it appears in.)

     
    • Anonymous

      Anonymous - 2003-02-09

      I built it and it works without changes. I have MinGW v3.2 / Dev-C++ v4.9.7.4.

      Clifford.

       
    • Nobody/Anonymous

      Please *STOP* hitting refresh!  You have posted the same thread 4 times laready!

      Wayne

       
    • Nobody/Anonymous

      "
      #include <iostream>
      using std::cout;
      using std::cin;
      using std::endl;
      using std::fixed;
      #include <iomanip>
      using std::setprecision;

      "
      Why don't you use

      #include <iostream>
      #include <iomanip>
      using namespace std;

      -rec

       
    • Nobody/Anonymous

      Note, when you post your compiler log, post it all, no just the errors.  One thing that earlier data shows is if, for some reason, you code compiled with gcc and not g++, which can lead to some problems for C++ code...

      You might want to do something to label you dummy input at the end...

      Oh yeah, it compiles and runs OK here, Dev 4.9.7.5/gcc-3.2

      Wayne

       

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.