i have question regarding ceil() function. following code try round 2 decimal places in c variable monthlypayment, , ceil function seems ignored in output. in image output compared supposed be. img
#include "stdafx.h" #include "stdio.h" #include "math.h" #define months 12 int main() { double principle; double rate; double numyears; double nummonths; double monthlypayment; double monthlyrate; printf("welcome morgage calculator.\nenter principal amount started. "); scanf_s("%lf", &principle); printf("enter yearly morgage interest rate "); scanf_s("%lf", &rate); printf("enter number of years "); scanf_s("%lf", &numyears); nummonths = numyears * months; monthlyrate = rate / months / 100; monthlypayment = ((monthlyrate) / (1 - pow((1 + monthlyrate), (-nummonths)))* principle); monthlypayment = monthlypayment * 100; ceil(monthlypayment); monthlypayment = monthlypayment / 100; double toprince = 0.0; double interest = 0.0; printf("your total monthly payment ammount:$ %.2lf\n", monthlypayment); printf("month\tprinciple\tinterest\t $ principle\n"); (int index = 1; index <= nummonths;) { interest = principle * monthlyrate; toprince = monthlypayment - interest; printf("%2d%16.2lf %16.2lf %16.2lf\n", index, principle, interest, toprince); principle = principle - toprince; index++; } }
ceil()
not alter variable provided returns result. should be:
double result = ceil(var);
Comments
Post a Comment