Thread: functions and passing data

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    104

    Question functions and passing data

    Im trying to take this code and modify it so that i have three funcations and pass data between the funcations. I have started to change the code and want to know if im on the right track,

    Code:
    /*************************************************************  
    File Name:     Tmitchellwk2
    Description:   Display Loan Amortization Schedule via functions
    Date:          Spetembet 16, 2006
    Designer;      Tabatha Mitchell
    Assignment:    week2
    Functions:	int CollectInput; This will collect the input and                  validate Input values
    	    int Calculate; this is where all of the calculations	
    		Will be done
    	    int Amortization:  This is where all of the data 	
    		will be printed  
    **************************************************************/
    #include <stdio.h>
    #include <math.h>
    
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate;
      double Amortization;
    
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
    
    
    /****************************************************************      
    //Start of the function to collect data
    /****************************************************************
     double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      {
    
       printf ("Please enter in loan amount, Term of Loan in months and Interest Rate.\n");
      
     
            while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
                         || (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
              {
                 while ((c = getchar()) != '\n' && c != EOF);
                 printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n"); 
             }         
                    CurrentBlance = LoanAmount;
                   Numberofmonths = TermLoan; 
                   i = InterestRate/ 100;    
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
       }  //end of collect data
    
    
    /********************************************************************
    Start of Calculate function
    /*************************************************************
     int Calculate ( int n, double a, double i);                
       {
              
        PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
       
                while(PaymentNumber < Numberofmonths)
               {
                        
               PaymentNumber++; //Start number of months for amortization schedule
               count++;
               AmountInterest = a  * (i/12);  
               AmountPrinciple = PaymentAmount - AmountInterest;
               LoanBlance = a - AmountPrinciple;
               
              a = LoanBlance;  
                    }//end of while loop 
       } //end of Calculate Function
    
    
    /**********************************************************************
    State of print function
    /*************************************************************
    int Amortization;
    {
              printf ("\amortization Schedule\n");
                printf ("_____________________\n");
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", InterestRate); 
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
    
    } //end of Amortization print function
    
    
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    printf ("hit enter to end");
    getchar ();
    getchar ();
    At least you have the printf() before the getchars() now. But I still think you should use this instead:
    Code:
    int c;
    while((c = getchar()) != '\n' && c != EOF);
    getchar();
    The variable c in CollectInput() isn't declared. Declare it as int c at the top of the function.

    Code:
    int Amortization;
    {
    ->
    Code:
    int Amortization(arguments)
    {
    +
    Code:
     double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      {
    ->
    Code:
     double CollectInput (double LoanAmount,  int TermLoan, double InerestRate)
      {
    +
    Code:
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate;
      double Amortization;
    ->
    Code:
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate(arguments);
      double Amortization(arguments);
    Functions have to be declared outside other functions; all your functions are currently inside main(). Move them outside, perhaps after main().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    Ok so i chagned the code. Can you also look at the while statments. I was told taht how i had it before was not checking the data. So i chagned it can you tell me if it is correct.

    Code:
    #include <stdio.h>
    #include <math.h>
    
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate(arguments);
      double Amortization(arguments);
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
    
    
    /****************************************************************      
    //Start of the function to collect data
    /****************************************************************
             double CollectInput (double LoanAmount,  int TermLoan, double InerestRate)
              {
                  printf ("Please enter in loan amount, Term of Loan in months and Interest Rate.\n");
                  scanf("%lf%d%f", &LoanAmount, &TermLoan, &InterestRate);
                  
                  while (Interest <= 0) 
                   {
                   printf ("Invalid entry. Re-enter Interest Rate:\n");
                   scanf ("\n%f", &InterestRate);
                       }
    
                            while (LoanAmount <= 0)
                             {
                             printf ("Invalid entry. Re-enter Loan Amount:\n")
     scanf ("\n%f", &LoanAmount);
      		 }
    
    while (TermLoan <= 0) 
    {
                  		printf ("Invalid entry. Re-enter Term of Loan:\n");
                 		 scanf ("\n%d", &TermLoan);
    }
    
     while ((c = getchar()) != '\n' && c != EOF);
      {
      printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n"); 
       }         
                    CurrentBlance = LoanAmount;
                   Numberofmonths = TermLoan; 
                   i = InterestRate/ 100;    
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
       }  //end of collect data
    
    
    /********************************************************************
    Start of Calculate function
    /*************************************************************
     int Calculate ( int n, double a, double i);                
       {
              
        PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
       
                while(PaymentNumber < Numberofmonths)
               {
                        
               PaymentNumber++; //Start number of months for amortization schedule
               count++;
               AmountInterest = a  * (i/12);  
               AmountPrinciple = PaymentAmount - AmountInterest;
               LoanBlance = a - AmountPrinciple;
               
              a = LoanBlance;  
                    }//end of while loop 
       } //end of Calculate Function
    
    
    /**********************************************************************
    State of print function
    /*************************************************************
    int Amortization(arguments);
    {
              printf ("\amortization Schedule\n");
                printf ("_____________________\n");
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", InterestRate); 
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
    
    } //end of Amortization print function
    
    
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    A bit better, but you still have stray semicolons after the function defintions
    Code:
    int Amortization(arguments);
    {
    and the functions are still all inside main(). And I didn't mean to put "arguments" there, I meant replace "arguments" with whatever arguments the function takes, such as nothing or "int x" or "int x, int y" or something.

    [edit]
    Code:
     while ((c = getchar()) != '\n' && c != EOF);
      {
      printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n"); 
       }
    I think you misunderstood what that loop does. It's equivalent to this:
    Code:
    for(;;) {
        c = getchar();
        if(c == '\n' || c == EOF) break;
    }
    That printf() isn't inside the loop. Notice the semicolon.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    104

    Talking

    ok i changed it again. I moved the statment so that it will look to see if there are any letter let me know if i did it right. I also moved my ; off of the funcations.

    Code:
     
    #include <stdio.h>
    #include <math.h>
    
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate(arguments);
      double Amortization(arguments);
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
    
    
    /****************************************************************      
    //Start of the function to collect data
    /****************************************************************
     double CollectInput (double LoanAmount,  int TermLoan, double InerestRate)
              {
                  printf ("Please enter in  Term of Loan “);
                  scanf ("\n%d", &TermLoan);
    while (TermLoan <= 0) 
    {
      while ((c = getchar()) != '\n' && c != EOF);
                  	  printf ("Invalid entry. Re-enter Term of Loan:\n");
                 	  scanf ("\n%d", &TermLoan);
     		  }
    
    
             	printf ("Please enter in  Interest “);
         	 scanf ("\n%f", &InterestRate);
           		while (Interest <= 0) 
                 		  {
                 		 while ((c = getchar()) != '\n' && c != EOF);
                   		printf ("Invalid entry. Re-enter Interest Rate:\n");
                  		scanf ("\n%f", &InterestRate);
                     		  }
    
            	 printf ("Please enter in  LoanAmount “);
    	scanf ("\n%f", &LoanAmount);
                            	while (LoanAmount <= 0)
                            		 {
                             		while ((c = getchar()) != '\n' && c != EOF);
                             		printf ("Invalid entry. Re-enter Loan Amount:\n")
     scanf ("\n%f", &LoanAmount);
      			 }
    
                    CurrentBlance = LoanAmount;
                   Numberofmonths = TermLoan; 
                   i = InterestRate/ 100;    
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
       }  //end of collect data
    
    
    /********************************************************************
    Start of Calculate function
    /*************************************************************
     int Calculate (arguments)              
       {
              
             PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
       
                while(PaymentNumber < Numberofmonths)
                 {
                        
                 PaymentNumber++; //Start number of months for amortization schedule
                 count++;
                 AmountInterest = a  * (i/12);  
                 AmountPrinciple = PaymentAmount - AmountInterest;
                 LoanBlance = a - AmountPrinciple;
                 a = LoanBlance;  
                    }//end of while loop 
       } //end of Calculate Function
    
    
    /**********************************************************************
    State of print function
    /*************************************************************
    int Amortization(arguments)
    {
              printf ("\amortization Schedule\n");
                printf ("_____________________\n");
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", InterestRate); 
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
    
    } //end of Amortization print function
    
    
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, good, the semicolons are gone.

    But this code
    Code:
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }
    is part of main, so any function between the start of main and this are inside main(). You need to move the whole of every function, from type name(){ to }, beyond this point.

    And you still have arguments instead of whatever your arguments are. If you don't intend to pass any arguments to the function, leave the space where arguments is empty.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    for the calculation it you be
    Code:
     int Calculate (int n, double a, double i
    fro the Amoritization it woule be
    Code:
     int Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate)
    the way that i have it set up is that it should get the data check it of its correct. pass it on to the calculate . then the ccalculate will pass it on to the print.

    wnd i also moved the return statement to this
    Code:
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }
    then i have the funcation below it. is this correct. Can i keep the doubles and the int defined in this main part of the program.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, your moving of the end of main() up to the top is correct. You can only use variables defined in main() in other functions if you pass those variables to the function. The changes made by the function won't be noticed in main() unless you pass a pointer to the variable or return the modified value.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    how do i pass my function from on to the other. So my program is still off in that matter

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    so i need to add a return to send the data to the next function In this prgram can i move my while statement out of the funcation have have it do a while statement the pull the funcations

    Code:
    /*************************************************************  
    File Name:     Tmitchellwk2
    Description:   Display Loan Amortization Schedule via functions
    Date: 	     Spetembet 16, 2006
    Designer;      Tabatha Mitchell
    Assignment:    week2
    Functions:	int CollectInput; This will collect the input and                 
    		 validate Input values
    	    int Calculate; this is where all of the calculations	
    		Will be done
    	    int Amortization:  This is where all of the data 	
    		will be printed  
    **************************************************************/
    #include <stdio.h>
    #include <math.h>
    
    double CollectInput (double LoanAmount,  int TermLoan, double InerestRate);
      double Calculate (int n, double a, double i);
      double Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate);
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
             PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
       
                while(PaymentNumber < Numberofmonths)
    {
    double Calculate (int n, double a, double i);
      double Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate);
    double Calculate (int n, double a, double i);
      double Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate);
    }
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }
    
    
    /****************************************************************      
    //Start of the function to collect data
    /****************************************************************
     double CollectInput (double LoanAmount,  int TermLoan, double InerestRate)
              {
                  printf ("Please enter in  Term of Loan “);
                  scanf ("\n%d", &TermLoan);
    while (TermLoan <= 0) 
    {
      while ((c = getchar()) != '\n' && c != EOF);
                  	  printf ("Invalid entry. Re-enter Term of Loan:\n");
                 	  scanf ("\n%d", &TermLoan);
     		  }
    
    
             	printf ("Please enter in  Interest “);
         	 scanf ("\n%f", &InterestRate);
           		while (Interest <= 0) 
                 		  {
                 		 while ((c = getchar()) != '\n' && c != EOF);
                   		printf ("Invalid entry. Re-enter Interest Rate:\n");
                  		scanf ("\n%f", &InterestRate);
                     		  }
    
            	 printf ("Please enter in  LoanAmount “);
    	scanf ("\n%f", &LoanAmount);
                            	while (LoanAmount <= 0)
                            		 {
                             		while ((c = getchar()) != '\n' && c != EOF);
                             		printf ("Invalid entry. Re-enter Loan Amount:\n")
     scanf ("\n%f", &LoanAmount);
      			 }
    
                    CurrentBlance = LoanAmount;
                   Numberofmonths = TermLoan; 
                   i = InterestRate/ 100;    
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
    return;
       }  //end of collect data
    
    
    /********************************************************************
    Start of Calculate function
    /*************************************************************
     int Calculate (int n, double a, double i)              
       {
                                  
                 PaymentNumber++; //Start number of months for amortization schedule
                 count++;
                 AmountInterest = a  * (i/12);  
                 AmountPrinciple = PaymentAmount - AmountInterest;
                 LoanBlance = a - AmountPrinciple;
                 a = LoanBlance;  
               
    return;
       } //end of Calculate Function
    
    
    /**********************************************************************
    State of print function
    /*************************************************************
    int Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate)
    {
              printf ("\amortization Schedule\n");
                printf ("_____________________\n");
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", InterestRate); 
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
     return;
    } //end of Amortization print function
    Last edited by redmondtab; 09-16-2006 at 02:49 PM.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
                while(PaymentNumber < Numberofmonths)
    {
    double Calculate (int n, double a, double i);
      double Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate);
    double Calculate (int n, double a, double i);
      double Amortization(double a, InterestRate, LoanBlance, PaymentNumber, AmountPrinciple, AmountInterest, Int InterestRate);
    }
    That's not how you call a function. How do you call printf()? puts()? Leave out the data type (double a, int interestrate) and the return type.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    104

    Question

    i need help. I have the program written with no code. But I'm having an issue getting to the functions . Need some help please
    Code:
     
    
    #include <stdio.h>
    #include <math.h>
    
    double CollectInput (double LoanAmount,  int TermLoan, double InterestRate, int c);
    double Calculate (int n, double a, double i)   ;
    double Amortization(double a, double InterestRate, double LoanBlance, double PaymentNumber, 
            double AmountPrinciple, double AmountInterest, int InterestRate);
    main  ()
    {
       
      
       int   TermLoan,  // length of the loan
             PaymentNumber,  //number of payments made
              Numberofmonths, //Number of months in the loan
              count,
              n,c; //Letters used for the calculations
    double   AmountPrinciple, //Amount paid on principle
             AmountInterest,  //amount paid to interest
             LoanBlance, //amount owed on loan\ count,
             CurrentBlance,
              LoanAmount, //amount of the loan  
             InterestRate, //interest rate on loan
               a,i,
               PaymentAmount;  //amount paid to loan 
    
    printf ("hit enter to end");
    getchar ();
    getchar ();
    return 0;         
    }
    
    //****************************************************************      
    //Start of the function to collect data
    //****************************************************************
    double CollectInput (double LoanAmount,  int TermLoan, double InterestRate, int c, double i, double n,
         double CurrentBlance,double Numberofmonths, double a, double PaymentNumber, int count)
         {
                     
            while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
                         || (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
              {
                 while ((c = getchar()) != '\n' && c != EOF);
                 printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n");
                 }
    
    
                    CurrentBlance = LoanAmount;
                   Numberofmonths = TermLoan; 
                   i = InterestRate/ 100;    
                   n = Numberofmonths;
                   a = CurrentBlance;
                    PaymentNumber = 0;
                    count = 0;  
       }  //end of collect data
    
    
    //********************************************************************
    //Start of Calculate function
    //*************************************************************
     double Calculate (int n, double a, double i, double PaymentAmout, double PaymentNumber, int Numberofmonths,
             double PaymentAmount, int count, double AmountInterest, double AmountPrinciple, double LoanBlance )               
       {
              
             PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));            
       
                while(PaymentNumber < Numberofmonths)
                 {
                        
                 PaymentNumber++; //Start number of months for amortization schedule
                 count++;
                 AmountInterest = a  * (i/12);  
                 AmountPrinciple = PaymentAmount - AmountInterest;
                 LoanBlance = a - AmountPrinciple;
                 a = LoanBlance;  
                    }//end of while loop 
       } //end of Calculate Function
    
    
    //*********************************************************************
    //State of print function
    //************************************************************
    double Amortization(double a, double LoanBlance, double PaymentNumber, double PaymentAmount,
           double AmountPrinciple, double AmountInterest, int InterestRate)
    {
              printf ("\amortization Schedule\n");
                printf ("_____________________\n");
               printf ("CurrentBlance %.2f\n", a);
               printf ("InterestRate %.2f\n", InterestRate); 
              printf ("PaymentNumber %d\n",  PaymentNumber);
              printf ("LoanBlance  %.2f\n", LoanBlance);
              printf ("PaymentAmount %.2f\n", PaymentAmount);
              printf ("AmountPrinciple %.2f\n", AmountPrinciple);
              printf  ("AmountInterest %.2f\n", AmountInterest);
              printf ("_______________________\n\n");
    
    } //end of Amortization print function

  14. #14
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    i need help. I have the program written with no code. But I'm having an issue getting to the functions . Need some help please
    What do u mean "written with no code". i dont see any function with no code. Your question dosn't make any real sense

    more over your program is not intended properly.

    ssharish2005

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    104
    im having issues calling the funcations into the program. So I need some help to see where I missed a step.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem passing data between functions
    By manutdfan in forum C Programming
    Replies: 9
    Last Post: 12-10-2006, 04:32 PM
  2. passing data between functions
    By nesagsar in forum C++ Programming
    Replies: 11
    Last Post: 12-08-2006, 12:48 PM
  3. Replies: 7
    Last Post: 04-19-2006, 11:17 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Replies: 4
    Last Post: 04-01-2003, 12:49 AM