### Changing program to use arrays.

I'm pretty new to programing and quite honestly I am struggling to learn it. I have been working on beginner programs that I find online but I can't seem to get the hang of arrays. Im attempting to change this loan program I wrote to use arrays but not sure how or where to start.
Any and all help is greatly appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129`` ``````#include #include #include #include using namespace std; double calculate_full_repayment(double p, int y, double i); double calculate_monthly_repayment(double p, int y, double i); void print_repayment(bool full_repayment, double p, int y, double i); int main() { int base_loan_years = 5; double base_loan_amount = 0; double base_loan_interest = 0.0; cout << "Welcome to Repayment of a Loan!\n\n"; cout << "Please enter the dollar amount of your loan: "; cin >> base_loan_amount; cout << "Please enter the starting interest rate (e.g. 4.75 for 4.75%): "; cin >> base_loan_interest; cout << "\n\n"; cout << fixed << setprecision(2) << "\t\t\t\tLoan of " << base_loan_amount << " dollars"; cout << "\n\n"; cout << "\t\t\t\t Monthly Repayment"; cout << "\n\n"; cout << "\t\t\t\t Interest Rates"; cout << "\n"; // Print header for years and rates. cout << "\tYears"; for (int i = 0; i < 5; i++) { double interest = (base_loan_interest + (0.5 * i)); cout << fixed << setprecision(2) << "\t" << setw(11) << right << interest << "%"; } cout << "\n"; // Print monthly payment. print_repayment(false, base_loan_amount, base_loan_years, base_loan_interest); cout << "\n"; cout << "\t\t\t\tTotal Amount Paid in Repayments"; cout << "\n"; // Print full re-payment amount. print_repayment(true, base_loan_amount, base_loan_years, base_loan_interest); return 0; } void print_repayment(bool full_repayment, double p, int y, double i) { // P = Base Loan Amount // I = Full Interest // Y = Base Year for (int row = 0; row < 6; row++) { for (int col = 0; col < 6; col++) { int years = y + (5 * row); if (col > 0) { double full_interest = (i + (0.5 * (col - 1))); double repayment; if (full_repayment) { repayment = calculate_full_repayment(p, years, full_interest / 100); } else { repayment = calculate_monthly_repayment(p, years, full_interest / 100); } cout << fixed << setprecision(2) << "\t\$" << setw(11) << right << repayment; } else { cout << "\t" << years; } } cout << "\n"; } } double calculate_full_repayment(double p, int y, double i) { // P = Principal // I = Interest // Y = Years // R = Monthly Repayment // F = Full Repayment Amount // 12 monthly repayments * number of years paid across // F = R * 12 * Y double f = calculate_monthly_repayment(p, y, i) * 12 * y; return f; } double calculate_monthly_repayment(double p, int y, double i) { // P = principal // I = Interest // Y = Years // R = Monthly Repayment // R = (P * (i / 12)) * (((1 + (i / 12)) ^ (12 * y)) / (((1 + (i / 12)) ^ (12 * y)) - 1)) // Calculate (1 + (i / 12)) ^ (12 * y) since it's used twice. double partial_work = pow((1 + (i / 12)), (12 * y)); double r = (p * (i / 12)) * (partial_work / (partial_work - 1)); return r; }``````
What is in your code that you want to implement as arrays? I don't understand your question.
 ... change this loan program I wrote to use arrays ...

arrays (either of the C-style or std variety) are simply containers that hold data of a certain type. So think of where in your program arrays might come into play - perhaps around line 42 - if you wish to store the interest data for which you'd need an array of doubles. Needless to say you'll find numerous examples of arrays in C++ online that will give you further illustrations of their uses
Topic archived. No new replies allowed.