Input:
staff name, the amount of loan, Year of Installment = 2 Process:
Do the decision
if (amount of loan < 5 000)
interest = 2
else if ( 10 000 < amount of loan >= 5 000)
interest = 2.5 else
Display “Invalid input. The maximum amount is RM10000”
interest = 0 Calculate Total of Interest
= (interest/100) * amount of loan
Calculate the Total Loan with Interest = amount of loan + Total of Interest
Calculate the monthly installment
= Total Loan with Interest / (Year of Installment * 12)
Output:
staff name, the amount of loan, monthly installment.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
string name;
double loan;
double interest;
int years = 2;
cout << "Enter staff name: ";
getline(cin, name);
cout << "Enter the amount of loan: ";
cin >> loan;
if (loan < 5000) {
interest = 2;
}
else if ( loan < 10000) {
interest = 2.5;
}
else {
cout << "Invalid input. The maximum amount is RM10000" << endl;
interest = 0;
}
double tot_interest = (interest/100) * loan;
double loan_with_interest = loan + tot_interest;
double monthly_installment = loan_with_interest / (years * 12);
cout << "Staff name: " << name << endl;
cout << fixed << setprecision(2);
cout << "The amount of loan: RM" << loan << endl;
cout << "The monthly installment: RM" << monthly_installment;
return 0;
}
Comments
Leave a comment