$\require{cancel}$
Principal: $100
Time : 1 year
Rate: 5% or 0.05
i = prt
i = 100 * 1 * 0.05 = 5.
payment = principal + interest
= 100 + 5
= $105
calculate the interest for the loan.
Get input Compute result Print output
Get principal Get time Get rate output principal, rate, time compute interest = principal * rate * time payment = principal + interest output interest and payment
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float principal{0},
interest{0},
rate{0},
time{0},
payment{0};
cout << fixed << setprecision(2);
cout << "Enter the principal: ";
cin >> principal;
cout << endl;
cout << "Enter the interest rate: ";
cin >> rate;
cout << endl;
cout << "Enter the time: ";
cin >> time;
cout << endl;
interest = principal * rate * time;
payment = interest + principal;
cout << "Principal: $" << principal << endl;
cout << "Rate: " << rate << "%" << endl;
cout << "Time: " << time << " years" << endl;
cout << "Interest: $" << interest << endl;
cout << "Payment: $" << payment << endl;
return 0;
}