I apologize if this is a dumb problem, but I really need help.
I have most of my program worked out, but I am having a hard time getting it to do what I want it to do. The idea is that in main, I call a function that opens an external file, allowing the user to enter the name, then passes the file to another function which is supposed to create and save data; it has to write columns, then call a function to calculate some info (this function then calls two other functions which each calculate a separate part of data this is to be printed to the file), then call a program to write the data to a file. I was doing OK until I got to the write part. I have worked on this all morning until I can't see straight, and I am totally lost now. The program compiles, but other than the header and column names, nothing is printed to the output file. Here is what I have put together so far, can someone please help me understand where I am going wrong and how to fix this?
Code:#include <iostream> #include <iomanip> #include <fstream> #include <cmath> #include <cstdlib> #include <fstream> #include <iostream> using namespace std; int openOutputFile(ofstream& o); void writeHeaderLinesToOutputFile(ofstream& o); int createAndSaveLoanData(ofstream& o); double calculateOneLineOfLoanResults(double r, double m); double calculatemonthlyPayment(double r, double m); double calculateTotalPayment(double& mPmt, double m); int writeLineOfResultsToOutputFile(ofstream& o, double r, double m, double& mp, double& tp); int main() { ofstream outFile; openOutputFile(outFile); cin.get(); return 0; } int openOutputFile(ofstream& outFile) { char outputName[50]; cout << "Please type the name of the output file, including the extension: "; cin >> outputName; outFile.open(outputName); if (outFile.fail()) { cerr << "Could not open " << outputName << "!" << endl; return EXIT_FAILURE; } createAndSaveLoanData(outFile); return 0; } int createAndSaveLoanData(ofstream& outFile) { double monthlyPmt, total; writeHeaderLinesToOutputFile(outFile); for (double r = .04; r < .0725 ; r + .0025) { for (double m = 240; m < 370; m + 60) { calculateOneLineOfLoanResults(r, m); writeLineOfResultsToOutputFile(outFile, r, m, monthlyPmt, total); } } return 0; } void writeHeaderLinesToOutputFile(ofstream& outFile) { outFile << "Loan Amount: $1000" << '\n' <<'\n'; outFile << left << setw(12) << "Interest" << left << setw(12) << "Duration" << left << setw(12) << "Monthly"; outFile << left << setw(12) << "Total" << '\n'; outFile << left << setw(12) << "rate" << left << setw(12) << "(years)" << left << setw(12) << "payment"; outFile << left << setw(12) << "payment" << '\n'; outFile.close(); } double calculateOneLineOfLoanResults(double rate, double months) { double monthlyPmt, total; monthlyPmt = calculatemonthlyPayment(rate, months); total = calculateTotalPayment(monthlyPmt, months); } double calculatemonthlyPayment(double rate, double months) { double ratem, expm, monthlyPmt; double loan = 1000; double e_to_the_m; ratem = rate / 1200; expm = (1.0 + ratem); e_to_the_m = pow(expm, months); monthlyPmt = (ratem * e_to_the_m * loan) / e_to_the_m - 1.0; return monthlyPmt; } double calculateTotalPayment(double& monthlyPmt, double months) { double total; total = monthlyPmt * months; return total; } int writeLineOfResultsToOutputFile(ofstream& outFile, double rate, double months, double& monthlyPmt, double& total ) { outFile << left << setw(12) << rate << left << setw(12) << (months / 12) << left << setw(12) << monthlyPmt; outFile << left << setw(12) << total << '\n'; outFile.close(); return 0; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.
CornedBee