Cis 170 Week 5 Project Car Loan Calculator

01 August, 2024 | 2 Min Read

CIS 170C

Course project

Week 5

#include < iostream >

#include <string>

#include < cmath >

#include <iomanip> #include <vector> using namespace std;

int main()

{

//Variables

vector<double> lengthOfLoan, amountOfLoan, interestRate;

vector<double> monthlyPayment(100), loanTotal(100), totalInterest(100); char yes;

const int INPUT_CUSTOMER = 1, DISPLAY_LOAN = 2, EXIT_PROGRAM = 3; vector<string> customerName; int choice; int numCustomers = 0; int index = 0; //Program

cout << “Welcome to the Car loan Calculator!\n”

<< “You will be asked to enter the amount of your Car loan,\n”

<< “the interest rate, and lenth you would like your Car loan for.\n”

<< “The program will then tell you your monthly Car payment.\n\n”; do

{ cout << " Car Loan calculator menu:\n\n"

<< “1. Enter customer information\n”

<< “2. See your loan information\n”

<< “3. exit the program\n\n”

<< “Enter a choice: “; cin » choice;

while (choice < INPUT_CUSTOMER || choice > EXIT_PROGRAM)

{ cout << “Please enter a valid menu choice: “; cin » choice;

}

if (choice == 1)

{ cout << “Please enter the number of customers you would

like\n”

<< " to enter loan Car information for: “; cin » numCustomers;

for (index = 0; index < numCustomers; index++)

{ string tempName; double tempAmountOfLoan, tempInterestRate,

tempLengthOfLoan;

cout << “Please enter the customers name: “; cin » tempName;

customerName.push_back(tempName); cout << “Please enter the loan amount: $"; cin » tempAmountOfLoan;

amountOfLoan.push_back(tempAmountOfLoan); cout << “Please enter the interest rate: “; cin » tempInterestRate;

interestRate.push_back(tempInterestRate); cout << “Please enter the length of the Car loan in

months: “; cin » tempLengthOfLoan;

lengthOfLoan.push_back(tempLengthOfLoan);

//Calculations

totalInterest[index] = amountOfLoan[index] *

interestRate[index]; loanTotal[index] = amountOfLoan[index] +

totalInterest[index]; monthlyPayment[index] = loanTotal[index] /

lengthOfLoan[index];

}

}

if (choice == 2) {

//Display monthly payment cout << fixed << setprecision(2);

for (index = 0; index < numCustomers; index++)

{

cout << customerName[index] << " your total loan is $”

<< loanTotal[index] << “\n”

<< “with a monthly Car payment of $” <<

monthlyPayment[index] << “\n”

<< “for " << lengthOfLoan[index] << " months with

an interest\n”

<< “rate of " << interestRate[index] << endl; }

}

} while (choice != EXIT_PROGRAM); system(“pause”);

return 0;

}

Related posts