Sep 12, 2012 at 3:08am UTC
My output keeps printing in scientific notation when I only want 2 decimals. Im using a file of 3 lines, each line is - last name, first name, salary, and increase rate; the output should be - first name, last name, new salary. How do I get it to output correctly?
#include <fstream>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
double salary;
double increase;
double newWage;
string firstName;
string lastName;
inFile.open("Ch3_Ex7Data.txt");
outFile.open("Ch3_ex7Output.dat");
outFile << fixed << showpoint;
outFile << setprecision(2);
inFile >> lastName >> firstName;
outFile << firstName << lastName << endl;
newWage = salary *( increase / 100) + salary;
inFile >> salary >> increase;
outFile << salary << increase << endl;
cout << firstName << " " << lastName << " $" << newWage << endl;
inFile.close();
outFile.close();
system("pause");
return 0;
}
Sep 12, 2012 at 6:13am UTC
Do you mean for cout ? You didn't use setprecision(2) for cout, you only did for outFile (2 different output streams)
Last edited on Sep 12, 2012 at 6:13am UTC