#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
usingnamespace std;
int main(int argc, constchar * argv[])
{
ofstream outFile;
outFile.open("outData.txt", ifstream::out);
if (!outFile) {
cerr << "Error: file could not be opened" << endl;
return -2;
}
ifstream inFile;
inFile.open("inData.txt", ifstream::in);
if (!inFile) {
cerr << "Error: file could not be opened" << endl;
return -1;
}
double salary, rate, newsal;
string fname, lname;
while (inFile >> lname >> fname >> salary >> rate) {
newsal = ((rate*.01) *salary) +salary;
outFile <<" "<< fname<<" "<< lname <<" "<<newsal << endl;
}
inFile.close();
outFile.close();
return 0;
}
I pretty sure it is an issue with
setprecision as I am not that strong in it.
but very possible I am wrong about this as well.
Thanks in advance for any help.
#include <iostream>
#include <iomanip>
int main()
{
constdouble d = 69079.4017607 ;
std::cout << d << '\n' ; // 69079.4
std::cout << std::fixed // in fixed point notation
<< std::setprecision(2) // with two digits after the decimal point
<< d << '\n' ; // 69079.40
std::cout << std::setprecision(3) // with three digits after the decimal point
<< d << '\n' ; // 69079.402
std::cout << std::setprecision(4) // with four digits after the decimal point
<< d << '\n' ; // 69079.4018
}