I am attempting to write some code that will open a sequintal file into arrays and will then can use the data to calculate monthly payment.

the text file is as follows

1 5 10 20 50
2.5 4.1 5.3 7.1 8.3

With the top row being yrs
and bottom row being intrest rates.

Ok -- so what is your question? If this is on your final exam then that means you are at the end of your course. At that point you should already know how to read a file into arrays.

Ok -- so what is your question? If this is on your final exam then that means you are at the end of your course. At that point you should already know how to read a file into arrays.

unfortunately thats not the case, the teacher gave us this problem and just told us to read a chapter that we never covered. The chapter she gave us is 9 chapters after the last chapter she covered with us, so reading it hasn't exactly helped.

And i'm sorry my question is can anyone give me any assistance?

Edited 6 Years Ago by bigdawgg: n/a

That's not a question, that's "Can someone please do my homework". Which unfortunately no one is going to do for you.

So, as with many problems, the first step is: break it up in parts.
-> Do you know how to open a file?
-> Do you know how to read from a file?
-> Do you know how to use arrays?
-> etc.

Maybe even those questions you can sub-divide. Then take what you think should be the first step, and try to implement it. If you don't know how... google, if you tried something but it doesn't work.. post here and give us your thoughts (how do YOU think it should by done, and why do YOU think it fails)... then someone will help you out.

Comments
Yes, that's what I meant too.
right on :)

That's not a question, that's "Can someone please do my homework". Which unfortunately no one is going to do for you.

So, as with many problems, the first step is: break it up in parts.
-> Do you know how to open a file?
-> Do you know how to read from a file?
-> Do you know how to use arrays?
-> etc.

Maybe even those questions you can sub-divide. Then take what you think should be the first step, and try to implement it. If you don't know how... google, if you tried something but it doesn't work.. post here and give us your thoughts (how do YOU think it should by done, and why do YOU think it fails)... then someone will help you out.

ahh dynamical problem solving :)) like it. xD

ahh dynamical problem solving :)) like it. xD

I'm not looking for anyone to do the work for me. I am looking to see if anyone can help me understand the process of openng a txt file into the code and reading it into an array.

Thank you

#pragma once
#include <cmath>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <iomanip>
using namespace std;
class Mortgage
{
private: 
int Amount, Term, monthTerm; 
double Interest, Payment, Interestpaid, setInterest;
public: 
void getAmount (); 
void rateTerm ();
void setrateTerm ();
void amort (); 
void Payments ();
};
void Mortgage::getAmount()
{
system("cls");
cout<< "1st natl Bank INC\n";
cout<<"\n\n";
cout<<"Enter Loan Amount (Dollars):$";
cin >>Amount;
}

void Mortgage::setrateTerm()
{
cout<<"\nEnter Term Length in years:";
cin >>Term;
cout<<"\n";
cout<<"Enter Interest Rate:";
cin >>Interest; 
}

void Mortgage::rateTerm()
{

int checklist = 0; 
int choice=0; 

do
{

cout<<"\n********Loan Menu*********";
cout<< "\n1) 1 year at 2.5% \n2) 5 years at 4.1% \n3) 10 years at 5.3% \n4 20 years at 7.1% \n5 50 years at 8.3%*******-\nEnter (1-5)";
cin >> choice;
checklist = 0; 
if(choice <= 0) 
{
system("cls");
cout<< "1st natl Bank INC\n";
cout<<"Loan Amount:$"<<Amount;
cout<<"\n\nError! Please enter only 1, 2, 3, 4, or 5 to select the term and rate\n";
checklist = 1;
} 
else if(choice == 1) 
{
ary=0;
}
else if(choice == 2) 
{
ary=1;
}
else if (choice == 3) 
{
ary=2;
}
else if (choice == 4) 
{ 
ary=3; 
}
else if (choice == 5) 
{
ary=4;

}
else if (choice > 5) 
{ 
system("cls");
cout<< "1st natl Bank INC\n";
cout<<"Loan Amount:$"<<Amount;
cout<<"\n\nError! Please enter only 1, 2, 3, 4, or 5 to select the term and rate\n";
checklist = 1;
}
}
while (checklist == 1);

void Mortgage::Payments()
{
system("cls");


Payment = (Amount * (((Interest/100)/12))/(1-pow((1+((Intere… - (Term*12))));

monthTerm = (Term*12);

Interestpaid = ((Interest/100)/12);
}
void Mortgage::amort()
{

int Month = 1; 
int pauselist = 5; 
double Newbalance; 
double Endingbalance; 
const char TAB='\t'; 
Newbalance = Amount; 

cout<<"\nWith a loan of $"<<Amount<<" for "<<Term<<" years\nat a "<<Interest<<"% Interest rate your \nmonthly payment will be $"<<Payment;
cout<<"\n----------------------------…
cout<<"\nPayment" "\tInterest Paid" "\tNew Balance\n";
while (monthTerm > 0)
{

Interestp = Interestpaid * Newbalance;

Endingbalance = Newbalance - Newbalance;


if (Newbalance > Payment)
{

cout.setf(ios::fixed);
cout<<"\n"<< Month<<TAB<<"$"<<setprecision (2) <<Interestp<<TAB<<TAB<<"$"<<setprecision (2) <<Newbalance - Payment + Interestp;


if (pauselist < 19)
{
++pauselist;
}
else
{
cout<<"\n";
system ("PAUSE");
pauselist = 0;
system("cls");
cout<<"Payment" "\tInterest Paid" "\tNew Balance\n";
}
}
else if (Newbalance <= Payment)
{
cout.setf(ios::fixed);
cout<<"\n"<< Month<<TAB<<"$"<<setprecision (2) <<Interestp<<TAB<<TAB<<"$"<<Endingbalanc…
pauselist = 0;
} 
Newbalance = Newbalance - Payment + Interestp; 
Month = ++Month; 
monthTerm= --monthTerm; 
}

}

char ch = 'y';
int menu = 0;
int main()
{
Mortgage loan;
do
{
system("cls");
cout<< "1st natl Bank INC\n";
cout << "\n\n**********Main Menu*********";
cout << "\n 1. Enter rate and term ";
cout << "\n 2. Select loan from menu ";
cout << "Press 1 or 2: ";
cin >>menu;

loan.getAmount();

if (menu == 1)
{
loan.setrateTerm();
}
if (menu == 2)
{
loan.rateTerm();
}

loan.Payments();
loan.amort();
cout<< "\nEnter another loan (y)es or (n)o):";

This is the code I have currently but the calculations for the monthly payments are not outputting correctly. I think it is caused by the info not being calculated properly.

Edited 6 Years Ago by WaltP: Added CODE Tags

Unfortunately, because there is no formatting at all, few of us are going to take the time to find the equations you're talking about in almost 200 lines. Check this out and repost with a little more detail.

unfortunately thats not the case, the teacher gave us this problem and just told us to read a chapter that we never covered. The chapter she gave us is 9 chapters after the last chapter she covered with us, so reading it hasn't exactly helped.

Good, so your teacher expects you to be at least somewhat capable of learning without handholding.
You say you're at the stage where you're prepping your final exam and you're still not able to read or think for yourself?
And you honestly expect to deserve to pass that exam?

Get reading, get studying, read those other chapters as well and understand them.
IF you ever graduate there'll be tons and tons of learning and reading to do with noone ever holding your hand.
Let this be a first attempt at doing so where the penalty for failure is having to retry the exam rather than loosing your job.

This question has already been answered. Start a new discussion instead.