Hello, I am doing a file input/output. I wrote 3 fulls names, phone number, balance. etc inside my input file.
Example:
John Doe 555-555-5555 5000.00
In my output file, I am trying to create this output with using setw.
First Name Last Name Phone Number Balance
------------ ------------ ----------------- ---------
John Doe 555-555-5555 5000.00
John Doe 555-555-5555 5000.00
I don't think ^^ will come out correctly on a forum post, but I want the firstname,lastname,phonenumber, and balance to appear underneath each other in a setw format which will look nice and neat. The results I'm getting is that the first name will look nice and neat, but the second name displayed underneath will be spaced out differently.
I don't know if my code is wrong, but I have tried for several hours rearranging code etc. Any help would be appreciated. Thanks
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
ifstream inData;
ofstream outData;
outData<<fixed<<showpoint;
outData.precision(2);
inData.open ("C++program.txt");
outData.open ("C++program_output.txt");
string firstname,lastname,phonenumber;
double balance;
outData<<"Call list for Customers who owe more than $1000"<<endl;
outData<<endl;
outData<<setw(1)<<"First Name"<<setw(16)<<" Last Name "<<setw(10)<<" Phone Number "<<setw(12)<<" Balance "<<setw(10)<<endl;
outData<<setw(1)<<"----------"<<setw(16)<<" --------- "<<setw(10)<<" ------------ "<<setw(12)<<" ------- "<<setw(10)<<endl;
while (inData)
{
inData>>firstname>>lastname>>phonenumber>>balance;
if ( balance > 1000 )
{
outData<<setw(1)<<firstname<<setw(18)<<lastname<<setw(18)<<phonenumber<<" $ "<<setw(5)<<setw(11)<<balance<<endl;
}
inData>>firstname>>lastname>>phonenumber>>balance;
}
inData.close();
outData.close();
system ("PAUSE");
return 0;
}