Question
Modify the attached program to do the following: Output results to a file in addition to showing the output on the screen. (i.e., The program
Modify the attached program to do the following:
- Output results to a file in addition to showing the output on the screen. (i.e., The program should produce a file that has the same content that is displayed on the screen.) Hint: Read through the code and look at the comments first!
I am not sure where to even begin on this any help will be appreciated.
#include
using namespace std;
int main() { // Input variables float loanAmt; // Amount of loan float yearlyInt; // Yearly interest int numYears; // Number of years
// Local variables float monthlyInterest; // Monthly interest rate int numberOfPayments; // Total number of payments float payment; // Monthly payment /* ADD CODE */ // Link to output file /* ADD CODE */ // Output file name
// Prompt user for output file name /* ADD CODE */
// Open output file /* ADD CODE */
// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* CHANGE CODE? */ cout << "Enter three values: " << " Loan amount, Yearly interest, and Number of years " << " Separate by spaces (Enter all 0's to quit): "; cin >> loanAmt >> yearlyInt >> numYears; cout << endl << endl;
while (loanAmt != 0){
// Calculate values monthlyInterest = yearlyInt / 12; numberOfPayments = numYears * 12; payment = (loanAmt * pow(monthlyInterest + 1, numberOfPayments) * monthlyInterest) / (pow(monthlyInterest + 1, numberOfPayments) - 1);
// Send output to file /* ADD CODE */
// Send output to screen cout << fixed << setprecision(2) << "Loan amount: $" << loanAmt << endl; cout << fixed << setprecision(2) << "Interest rate: " << yearlyInt << endl; cout << "Years: " << numYears << endl << endl;
cout << "Your monthly payments are $" << payment << endl << endl << endl;
// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* CHANGE CODE? */ cout << "Enter the loan amount, yearly interest, and number of years separated by spaces (0's to quit): "; cin >> loanAmt >> yearlyInt >> numYears; cout << endl << endl; }
// Close file (necessary?) /* ADD CODE */
cout << "Good bye!" << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started