mình có cái bài tập cơ bản như thế này nhưng ko hiểu sao nó ko tính được
khi nhập theo thứ tự principal = 10.000, rate = 8, years = 4, income = 2000 thì repayment là 244.13 nhưng khi nhập thì kết quả lại ra có 0.28
đây là bài tập cơ bản nhưng nó có luôn kết quả trong sách là repayment = 244.13
ko có lẽ nào lại ra 0.28, ko bít mình làm sai chỗ nào nữa hix
có ai giải thix cho mình dùm
Code:
#include <stdio.h>
#include <conio.h>
int main(void)
{
float years = 0.0;
float principal = 0.0;
float rate = 0.0;
float repayment = 0.0;
float income = 0.0;
clrscr();
printf("The principal for loan is: ");
scanf("%f", &principal);
printf("The annual rate for loan is: ");
scanf("%f", &rate);
printf("The years for loan is: ");
scanf("%f", &years);
printf("The monthly income is: ");
scanf("%f", &income);
repayment = principal * ( 1 + ( rate * years ) / 100.0 ) / ( 12 * years );
printf("The monthly repayment of %.2f and %.2f in %.1f years is %.2f", principal, rate, years, repayment);
printf("\nThe monthly income is:%.2f", income);
if(repayment > 0.25 * income)
{
printf("\nNo Loan");
}
else
{
printf("\nLoan ok");
}
getch();
return 0;
}
Nhắc nhở.Code để trong tag [code],cảm ơn.Alviss