Results 1 to 4 of 4

Thread: The output isnt correct.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    40

    The output isnt correct.

    Code:
    #include "amort.h" 
    #include <stdio.h>
    #include <stdlib.h>
    #include <process.h>
    #include<ctype.h>
    #include<conio.h>
    
    //extern double getPaymentAmount(double principal,int numberOfMonths,double interest);
    //extern double getLoanAmount(double payment,int numberOfMonths,double interest);
    //extern int getNumberOfMonths(double payment, double principal,double interest);
    
    int main(void)
    {
    	
    	int choice;
    	int	numberOfMonths;
    	int months;
    	float interest;
    	double principal;
    	double payment;
    
    	do
    	{
    		system("cls");
    		printf("Welcome to Amortization Calculator by Yongho Kim\n");
    		printf("==========================================\n");
    		printf("1.calculate size of payments\n");
    		printf("2.calculate size of the loan\n");
    		printf("3.calculate number of payments\n");
    		printf("4.exit\n");
    		printf("==========================================\n");
    		scanf("%d",&choice);
    		switch(choice)
    		{
    			case 1:
    			printf("Enter annual interest rate: ");
    			scanf("%f",&interest);
    			while(interest<=0)
    			{
    
    				printf("annual interest rate should be >0: ");
    				scanf("%f",&interest);
    			}
    			printf("\nInterest rate: %.2f\n",interest);
    			printf("Enter principal amount: ");
    			scanf("%lf",&principal);
    			printf("\nPrincipal amount:$ %.2f\n",principal);
    			printf("Enter number of months: ");
    			scanf("%d",&numberOfMonths);
    			printf("\nNumber of months: %d\n",numberOfMonths);
    			payment = getPaymentAmount(interest,numberOfMonths,principal/1200);
    			printf("Payment Amount=$ %.2lf",payment);
    			break;
    	
    			case 2:
    			printf("Enter annual interest rate: ");
    			scanf("%lf",&interest);
    			while(interest<=0)
    			{
    				printf("annual interest rate should be >0: ");
    				scanf("%lf",&interest);
    			}
    			printf("\nInterest rate:$ %.2f\n",interest);
    			printf("Enter payment amount: ");
    			scanf("%lf",&payment);
    			printf("\nPayment amount:$ %.2f\n",payment);
    			printf("Enter number of months: ");
    			scanf("%d",&numberOfMonths);
    			printf("\nNumber of months: %d\n",numberOfMonths);
    			principal = getLoanAmount(payment,numberOfMonths,interest/1200);
    			printf("Principal Amount=$ %.2lf",principal);
    			break;
    	
    			case 3:
    			printf("Enter annual interest rate: ");
    			scanf("%lf",&interest);
    			while(interest<=0)
    			{
    				printf("annual interest rate should be >0: ");
    				scanf("%lf",&interest);
    			}
    			printf("\nInterest rate:$ %.2f\n",interest);
    			printf("Enter principal amount: ");
    			scanf("%lf",&principal);
    			printf("\nPrincipal amount:$ %.2f\n",principal);
    			printf("Enter payment amount: ");
    			scanf("%d",&payment);
    			printf("\nPayment amount:$ %.2f\n",payment);
    			months = getNumberOfMonths(payment,principal,interest/1200);
    			printf("NUmber of months= %d",months);
    			break;
    	
    			case 4:
    			return 1;
    		}
    		printf("\n\n\n\nWould you like to start over? Y/N");
    	}while( getch() == 'y' || getch() == 'Y');
    
    	return 1;
    }
    
    
    
    =====================
    
    #include "amort.h" 
    #include <math.h>
    //----------------------------------------------------------------------------
    //
    //----------------------------------------------------------------------------
    double getPaymentAmount(double interest, int numberOfMonths, double principal)
    {
    	double numerator,denominator;
    		numerator= powf((1+interest),numberOfMonths)*principal*interest;
    		denominator=powf((1+interest),numberOfMonths)-1;
    
    	return numerator/denominator;
    }
    //----------------------------------------------------------------------------
    //
    //----------------------------------------------------------------------------
    double getLoanAmount(double interest, int numberOfMonths, double payment)
    {
    	double numerator,denominator;
    		numerator=powf((1+interest),numberOfMonths) - 1*payment;
    		denominator=interest*powf((1+interest),numberOfMonths);
    
    	return numerator/denominator;
    
    }
    //----------------------------------------------------------------------------
    //
    //----------------------------------------------------------------------------
    int getNumberOfMonths(double interest, double payment, double principal)
    {
    	double numerator,denominator;
    		numerator=log(payment)-log(payment-(principal*interest));
    		denominator=log(1+interest);
    
    	return numerator/denominator;
    }
    
    
    
    ===============
    
    #ifndef AMORT_H
    #define AMORT_H
    #include <math.h>
    
    #pragma once
    
    	double getPaymentAmount(double principal,int numberOfMonths,double interest);
    	double getLoanAmount(double payment,int numberOfMonths,double interest);
    	int getNumberOfMonths(double payment, double principal,double interest);
    
    #endif
    the output that im suppose to get isnt right... it keeps giving me random numbers or too high. can someone help me with this??
    and is there a way to calcuclate the interest and print it on the console system?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: The output isnt correct.

    You are way to vague in your problem description. What exactly is your code supposed to do? What output are you expecting?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2011
    Posts
    40

    Re: The output isnt correct.

    Payment amount and interest. User inputs three informations

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: The output isnt correct.

    I didn't see this thread until now. I posted in your other thread. Please refrain from re-posting the same question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width