Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include // Access power function #include // Access manipulators /* ADD CODE */ // Access file i/o functions

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

How are monopolies and monopolistic competitive firms profitable

Answered: 1 week ago

Question

Developing and delivering learning that is integrated with the job.

Answered: 1 week ago

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago