Sponsored Content
Top Forums Programming Bad Mortgage Calculation Code Post 302117115 by Aaron Van on Thursday 10th of May 2007 10:56:16 PM
Old 05-10-2007
Bad Mortgage Calculation Code

Hello,

I'm teaching myself C and attempting to write a little program that will calculate the monthly payments on a fixed-rate mortage:

/* Aaron's mortgage foo */
// mortgage.c
#include <stdio.h>
#include <math.h>

int main(void)

{
float interestRate; // The bank's fixed interest rate
float interest; // monthly interest rate
int mortgage; // Cost of the house
int term; // How many years is the mortgage
int totMonths; // total number of payments
float monthlyPayment; // Your monthly mortgage payment

interest = interestRate / 1200;
totMonths = term / 12;

printf("How much is the mortgage? ");
scanf(" %d", &mortgage);

printf("For how many years? ");
scanf(" %d", &term);

printf("What is the bank's interest rate? ");
scanf(" %f", &interestRate);

monthlyPayment = mortgage * pow(1 + interest, totMonths) * interest / pow(1 + interest, totMonths) - 1;

printf("Your monthly payments are %.2f\n.", monthlyPayment);
return 0;
}



When I fat-finger the numbers into a calculator I get correct answers so I think monthlyPayment formula is accurate; however, program outputs monthly payments of -1.00 no matter what numbers I input. Obviously, I'm overlooking something. Any help? Thanks.
 

We Also Found This Discussion For You

1. Programming

C code 1ULL and bit calculation

I found this block of C code to create combinations of A, T, C & G characters (DNA bases). Can anybody explain this code for me, especially with 1ULL<< and ? 16 for (x = 0; x < 1ULL << (2 * k); ++x) 17 { 18 for (i = 0, y = x; i < k; ++i, y >>= 2) 19 putchar ("ACGT"); 20 }... (3 Replies)
Discussion started by: yifangt
3 Replies
monthly(8)						      System Manager's Manual							monthly(8)

NAME
monthly - httpd log rotation for wwwstat SYNOPSIS
monthly DESCRIPTION
THIS PROGRAM MUST ONLY BE RUN ONCE PER MONTH! DURING THE FIRST WEEK It assumes a lot, like that you use wwwstat and archive your logfiles once per month. You will need to configure it for your server before it can be used. Reads the logfile (assumed to contain more than one month's worth of WWW common logfile entries) and moves the prior month's entries into a separate file. The new file is created on TMPDIR (to avoid filling up the disk), compressed using gzip, and then moved to the archive directory. The program also restarts the httpd server. SEE ALSO
crontab(1), httpd(1m), perl(1), wwwstat(1), splitlog(1), wwwerrs(8), oldlog2new(8) More info and the latest version of monthly can be obtained from http://www.ics.uci.edu/pub/websoft/wwwstat/ ftp://www.ics.uci.edu/pub/websoft/wwwstat/ If you have any suggestions, bug reports, fixes, or enhancements, please join the <wwwstat-users@ics.uci.edu> mailing list by sending e- mail with "subscribe" in the subject of the message to the request address <wwwstat-users-request@ics.uci.edu>. The list is archived at the above address. 18 November 2004 monthly(8)
All times are GMT -4. The time now is 11:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy