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.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-02-09
I built it and it works without changes. I have MinGW v3.2 / Dev-C++ v4.9.7.4.
Clifford.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.)
I built it and it works without changes. I have MinGW v3.2 / Dev-C++ v4.9.7.4.
Clifford.
Please *STOP* hitting refresh! You have posted the same thread 4 times laready!
Wayne
"
#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
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