I am having a problem writing from a outside file. here is the assignment.
Write the program as an object-oriented C++ program that allows the user to select which way they want to calculate a mortgage: by input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment or by input of the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.5%, and 30 year at 5.75% (use an array for the mortgage information and read the interest rates to fill the array from a sequential file). In either case, display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. On longer term loans, the
list will scroll off the screen. Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list. Allow the user to loop back and enter a new amount and make a new selection, or quit. Insert comments in the program to document the program.
I am not sure if i am doing it right, of if i am just way off. Can someone help me?
Here is my main file:
//Jeremy Johnson
//PRG 411
//Instructor: Charles Ford
#include "mortgageCalc_JeremyJohnson.h"
#include <math.h>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main () {
MortgagePayment totalMort;
double interestRate[]= {5.35, 5.5, 5.75,};//*Annual interest rate
double years[]= {7, 15, 30,}; //*Term of the loan
double rate = 0;// Rates
double term = 0;// Term
double interestPaid; //Interest paid out
double balance; //total Loan Balance
double paidOut; //Amount Paid on Loan
double NumOfPymts; //total Number of Payments
int Monthly; //*Allows loop for loan balance and interest paid
int listScroll = 0; //*Scroll List for loan balance and interest paid
char choice; //User chooses to enter Int and term or select scenario
bool doneEndProg = false;
do {
totalMort.openingHead();
totalMort.enterPrincipal();
cout<< "Would you like to me to provide options, or would you like to make the choices yourself??" << endl;
cout<< "Press 1 for me to provide options, or 2 to make your own choices" <<endl;
cin >> choice;
if (choice == '1') {
/*
cout << "Your Terms and Rates are as followed. Please make a choice: " << endl;
cout << "1. 7 years at 5.35%" << endl;
cout << "2. 15 years at 5.5%" << endl;
cout << "3. 30 years at 5.75%" << endl;
cout << "What is your selection:" << endl;
*/
int iarray[3] = {0};
float farray[3] = {0.0F};
ifstream in("cr15.txt");
in >> iarray[0] >> iarray[1] >> iarray[2];
in >> farray[0] >> farray[1] >> farray[2];
// do the same with the float array
int select;
cin >> select;
switch (select) {
case 1:
cout << "You have selected 7 Years and 5.35%" << endl;
break;
case 2:
cout << "You have selected 15 Years at 5.50%" << endl;
break;
case 3:
cout << "You have selected 30 Years at 5.75%" << endl;
break;
default:
cout << "Invalid choise. You have chosen poorly..." << endl;
cout << "Please correct your choice" <<endl;
cin >> select;
return 0;
}
rate = interestRate[select - 1];
term = years[select - 1];
}
else if (choice == '2') {
cout << "Enter your desired rate: ";
cin >> rate;
cout << "Enter your desired term(in years): ";
cin >> term;
}
//calculate monthly payment
double tPayment = (totalMort.principal * ((rate/1200)/(1 - pow((1+(rate/1200)),-1*(term*12)))));
cout << "These were your choices:" << endl;
cout << "Interest Rate: "<< rate << "\n";
cout << "Term: " << term << " Years\n" << endl;
//Ouput payment
cout << "Based on your answers above, here are the results of your answers: \n" << endl;
cout << "Your Total Monthly Payment is: $" << tPayment << "\n" << endl;
//Number of Payments,
NumOfPymts = term * 12;
listScroll = 0;
for (Monthly = 1; Monthly <= NumOfPymts && toupper(choice) != 'D'; ++Monthly) {
interestPaid = totalMort.principal * (rate / 1200);
paidOut = tPayment - interestPaid;
balance = totalMort.principal - paidOut;
if (balance < 0) {
balance = 0;
}
totalMort.principal = balance;
//This will Scroll and seperate the loan balance and Interest paid
if (listScroll == 0) {
cout << "Balance" << "\t\t\tTotal Interest Paid" << endl;
}
cout << setprecision(2) << fixed << "$" << setw(5) << balance << "\t\t\t\t$"<< setw(5) << interestPaid << endl;
++listScroll;
/*Allows the user to enter a value to see the remaining information after 12 lines,
to clear the list and enter new values, or to quit.
*/
if (listScroll == 12) {
cout << "Would you like to play again?\n" << endl;
cout << "Enter 'S' to scroll through the list, Enter 'C' to continue and try again, Enter 'E' to quit and be done.\n" << endl;
cin >> choice;
if (choice == 'S' || choice == 's') {
listScroll = 0;
}
else {
if (choice == 'C' || choice == 'c') {
break;
}
else if (choice == 'E' || choice == 'e') {
doneEndProg = true;
}
}
}
}
}
while ( choice != 'E' && choice != 'e' );
return 0;
}
Here is my other file that is part of the assignment:
//Jeremy Johnson
//PRG 411
//Instructor: Charles Ford
#include "mortgageCalc_JeremyJohnson.h"
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
void MortgagePayment::openingHead() //This is an opening for the program....nothing more...
{
cout <<"\n\t\t Jeremy Johnson's Mortgage Calculator\n\n";
cout << "\tWrite the program as an object-oriented C++\n";
cout <<"\tprogram that allows the user to select which way\n";
cout << "\tthey want to calculate a mortgage: by input of the amount\n" ;
cout << "\tof the mortgage, the term of the mortgage, and the interest\n" ;
cout << "\trate of the mortgage payment or by input of the amount of a\n";
cout << "\tmortgage and then select from a menu of mortgage loans:\n";
cout << "\t\t- 7 year at 5.35%\n";
cout << "\t\t- 15 year at 5.5%\n";
cout << "\t\t- 30 year at 5.75%.\n";
cout << "\tIn either case, display the mortgage payment amount. Then, list\n";
cout << "\tthe loan balance and interest paid for each payment over the\n" ;
cout << "\tterm of the loan. On longer term loans, the list will scroll off\n";
cout << "\tthe screen. Do not allow the list to scroll off the screen, but\n" ;
cout << "\trather display a partial list and then allow the user to continue\n";
cout << "\tthe list. Allow the user to loop back and enter a new amount and\n" ;
cout << "\tmake a new selection, or quit. Insert comments in the program to\n" ;
cout << "\tdocument the program.";
cout <<"\n____________________________________________________________________\n\n " <<endl;
}
void MortgagePayment::enterPrincipal() //This is the function for the user input of loan amount
{
cout << "\t\tEnter the total amount of the loan:$ "; //User input
cin >> this->principal;
}
here is the header file
//Jeremy Johnson
//PRG 411
//Instructor: Charles Ford
class MortgagePayment {
public:
void openingHead(); //Introduction to the program
void enterPrincipal(); //This is where the principle is entered
double principal; //principle
double interest; //Interest
int term; //Term
};
Here is the cr15.txt
7 5.35
15 5.5
30 5.75
Thank you everyone!! Any help from your guys would be great.