Question
Modify the attached program to do the following: Rather than taking input from the keyboard it should get its inputs from a data file. Note:
Modify the attached program to do the following:
- Rather than taking input from the keyboard it should get its inputs from a data file. Note: Since input is coming from the file, nothing needs to be displayed on the screen until the output is displayed.
#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 input file /* ADD CODE */ // Input file name
// Prompt user for input file name /* ADD CODE */
// Open input file /* ADD CODE */
// Get first line of data from file /* ADD CODE */
// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* STILL NEEDED? */ 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;
// Loop until user enters 0... /* CHANGE CODE */ 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 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;
// Get next line of data from file /* ADD CODE */
// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* STILL NEEDED? */ 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