Printing a created file

My program is suppose to read an input file and print it contents which it does and then it is suppose to adjust it and create a new file that contains the adjustments.The new file is created properly and has the correct contents but when I try print the contents only the headers show up. Any feedback would be helpful. There are other functions but I believe they aren't causing the problem. We aren't allowed to adjust the main, only the other functions.


#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

// Function prototypes
void ProcessAccounts(std::ifstream &ifile, std::ofstream &ofile, double rate);
void PrintFileContents(std::ifstream &str);
std::ifstream GetInputFile(std::string filename);
std::ofstream GetOutputFile(std::string filename);
void SetInputStreamPos(std::ifstream &str, int pos);
void SetOutputStreamPos(std::ofstream &str, int pos);



//[BEGIN MAIN]
int main()
{
std::string inputFileName;
std::string outputFileName;
double interestRate;

std::cout << "Enter an input filename: ";
std::cin >> inputFileName;
std::cout << "Enter an output filename: ";
std::cin >> outputFileName;
std::cout << "Enter an interest rate (%): ";
std::cin >> interestRate;

std::cout << std::endl;
std::ifstream ifile = GetInputFile(inputFileName);
std::ofstream ofile = GetOutputFile(outputFileName);

std::cout << "Current account status:" << std::endl;
PrintFileContents(ifile);

ProcessAccounts(ifile, ofile, interestRate);

ifile.close();
ofile.close();

std::cout << std::endl;
std::cout << "New account status:" << std::endl;
ifile = GetInputFile(outputFileName);

PrintFileContents(ifile);

ifile.close();

std::cout << "Press ENTER";
std::cin.ignore();
std::cin.get();
return 0;
}



void PrintFileContents(std::ifstream &str)
{
// Print the contents of the file
// First, print the file headers
// Then, print each line.
// Make sure the text is properly formatted
// Remember the functions available in iomanip?

// EXAMPLE:
// Name Savings Credit
// Bob $23.56 $0.00
// Joe $43.52 $0.00
// Sally -$1.58 $0.00

// Put your code here
std::string name;
double savings;
double credit;
SetInputStreamPos(str, 0);
std::cout << "Name" << std::setw(12) << "Savings" << std::setw(12) << "Credit " << std::endl;
while (str >> name >> savings >> credit )
{
std::cout << name;
if (savings >= 0)
{
std::cout << std::setw(8) << " $" << std::setprecision(2) << std::fixed << savings;
std::cout << std::setw(6) << " $" << std::setprecision(2) << std::fixed << credit;
std::cout << "\n";
}
else if (savings < 0)
{
savings = savings * (-1);
std::cout << std::setw(6) << "-$" << std::setprecision(2) << std::fixed << savings;
std::cout << std::setw(7) << " $" << std::setprecision(2) << std::fixed << credit;
std::cout << "\n";
}
}


}
Topic archived. No new replies allowed.