CIS170C WEEK 4 PROJECT-Lucky Duck Car Loan Calculator.docx

30 July, 2024 | 2 Min Read

Course Project Week 4

Code:

#include < iostream >

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

void main()

{

//user input //declare variables int choice = ' ‘;

float amountBorrowed, interestRate, totalInterest, loanTerm, loanTotal,

total, monthlyRate, mainMenu; cout << endl;

cout << “Welcome to Lucky Duck Car Loan Calculator” << endl; //menu header cout << “****************************************” << endl; cout << " Main Menu " << endl; cout << " Please select an option to begin " << endl; cout << endl; //menu options

cout << “****************************************” << endl; cout << “[1] Open a loan application” << endl; cout << “[2] Exit Program” << endl;

cout << “****************************************” << endl; cin » choice; if (choice == 1)

{

cout << “Please enter the amount you would be borrowing: " << endl;

//insert loop for certain amount range cin » amountBorrowed;

while (amountBorrowed < 50000 || amountBorrowed > 100000)

{ cout << “Loan amounts can only range from $50,000 to

$100,000.” << endl; cout << “Please enter amount within $50,000 and $100,000.” <<

endl; cin » amountBorrowed;

}

cout << “Please enter the preferred interest rate: “; cin » interestRate;

}

if (choice == 2)

{ cout << “Thanks for using the Lucky Duck loan calculator!"; return;

}

//condtional expression asking if cx wants 5 year OR 7 year loan cout << “Which would you prefer? 5 or 7 year car loan: Enter 5 or 7: " <<

endl; cin » loanTerm;

total = (loanTerm*amountBorrowed) +

( loanTerm*amountBorrowed*(interestRate / 100.00));

{if (loanTerm == 5)

//calculate for 5 year loan

{

monthlyRate = total / (loanTerm * 60);

cout << “Your monthly rate for 5 years (60 months) is: " <<

monthlyRate << endl;

}

else

{ if

//calculate for 7 year

( monthlyRate = total / (loanTerm * 84)); cout << “Your monthly rate for 7 years (84 months) is: " <<

monthlyRate << endl;

}

}

//calculations processing

totalInterest = amountBorrowed * interestRate; loanTotal = (amountBorrowed + totalInterest); monthlyRate = loanTotal / loanTerm;

//data output/display

cout << “Your total car loan amount is: " << total << endl; cout << endl;

cout << “Balance towards interst is: " << total - (loanTerm*amountBorrowed)

<< endl; cout << “Would you like to return to the main menu? Y or N” << endl; cin » mainMenu;

if (mainMenu == ‘Y’ || mainMenu == ‘y’) ;

{ main();

}

{ if (mainMenu == ‘N’ || mainMenu == ‘n’) ;

}

system(“pause”) ; }

Related posts