Help with multi function progam

This is a discussion on Help with multi function progam within the C Programming forums, part of the General Programming Boards category; I am working on a program with more than one function. The proble, is after I have written the different ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Help with multi function progam

    I am working on a program with more than one function. The proble, is after I have written the different short programs I needed to make them into one program. Now that I did that is were I am haveing problems. Can anyone help me with what I am doing worng.

    Thank You
    Wacko

    Code:
    #include "stdafx.h"
    #include <math.h>
    
    #using <mscorlib.dll>
    
    using namespace System;
    
    void display_statement (double, double, double, double, int, double);
    
    
    
    int _tmain()
    
    {
    double a=1;
    double b=1;
    double c=1;
    double d=1;
    double e=1;
    double x=1;
    double i;                     // Interest_Rate Monthly
    double p;                     // Principal
    int n  ;                      // Number Payments
    double Payment_Amount;
    double payment;
    double Total_Amount;
    double total_amount;
    double Tamount_paid;
    double total_interest;
    double Tinterest_paid(double, int);
    double payment_amount (double, double, int);
    
    
    	printf("Please Enter Interest Rate ");            // Key As n.n
    		scanf("%lf",&i);
    	printf("Please Enter Loan Amount ");              // Amount of Loan
    		scanf("%lf",&p);
    	printf("Please Number Of Monthly payments ");     // Number Of Monthly 
    		scanf("%d",&n);
    
    	payment = Payment_Amount (i,p,n);
        Total_Amount = Tamount_paid(payment,n);
        total_interest=Tinterest_paid(total_amount,p);
    
    void display_statement (double, double, double, double, int, double);
    
    }
    
    {
    	double x;
    
    	x = Tinterest_paid(200000, 150000);
    	printf("The result is\n\n %f', X);
    
    		return 0;
    
    
    
    }
    
    double Tinterest_paid (double amount_paid, double Principal)
    
    {
    
    	double int_paid;
    
    	int_paid = amount_paid - Principal;
    
    	return (int_paid);
    
    {
    
    	double x;
    	x = Payment_Amount(5.5, 100000, 60);
    
    }
    
    double Payment_Amount (double Interest_Rate, double Principle, int Number_Payments)
    
    {
    	double a, payment;
    
    	a = Interest_Rate/100;
    	a= a/12;
    
    	payment = (a* Principle)/ (1 - pow((1+a), -Number_Payments));
    	return(payment);
    }
    
    {
    	display_statement (a, b, c, d, x, e);
    	return 0;
    
    }
    
    void display_statement (double payment, double loan_payment, double Tinterest, double Principal, int Number_Payments, double interestrate)
    
    {
    
    	printf("Monthy Payment: $%.2f\n\n", payment);
    	printf("Total Loan Amount; $%.2f\n\n", loan_Amount);
    	printf("Total Interest Payment: $%.2f\n\n", Tinterest);
    	printf("Principal: $%.2f\n\n", Principal);
    	printf("Number Of Payments: %d\n\n", Number_Payments);
    	printf("Interest Rate %.3f percent\n\n", interestrate);
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    Code:
    void display_statement (double, double, double, double, int, double);
    
    }
    
    {
    	double x;
    
    	x = Tinterest_paid(200000, 150000);
    	printf("The result is\n\n %f', X);
    
    		return 0;
    
    
    
    }
    What in the world is going on here? First of all, your braces are all screwed up. Secondly, you need to include variables names in the function parameter list - not just their types. Thirdly, you have a semicolon after the function declaration. Or is this even a function declaration? I can't really tell.

    Also, how are you using a namespace in a C program? If you intended for this to be C++, then post it in the appropriate forum.

    And then there seems to be these mysterious blocks of code which don't exist in any function. You need to stop what you are doing, and spend some time reading some C tutorials.

    Code:
    #using <mscorlib.dll>
    Are you kidding me?...

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    I am useing .Net for the complier

    As for the rest, this is why I am asking for help.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    Well first you need to decide what language you actually want to program in. I think I see some managed C++ in your code there, is that what you want?

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    No I am doing this in C.

    Thank You for helping me, I also want to learn what I am doing wrong.

    Thanks

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    I also want to learn what I am doing wrong
    Unfortunately, the answer to that is everything. Like I said before, you need to read some C tutorials before going any further in your current program.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    I understand That I am new to this, but I would like some help as to what I did worng. I was able to write different parts of the program and didn't have any problems running thoses part by themself, the problem I have is when I try to join things into one program.

  8. #8
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    List of things wrong (incomplete, but a start)

    - You have no main() function.
    - You are trying to declare/define functions within other functions, you can't do that.
    - No such thing as #using in C
    - No such thing as using namespace in C
    - You seem to have blocks of code appearing in the middle of nowhere.

  9. #9
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    I am useing Visual Studio .Net to write my code. I am going to do some of what you said. I not sure what you said about not haveing a main() I thought I did.

    Thanks

  10. #10
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    I have rem out some of what you said is worng, now I don't have as many errors as before, but I still am haveing problems. Can you help me some more.

    Thank You

    Code:
    // This is the main project file for VC++ application project 
    // generated using an Application Wizard.
    
    #include "stdafx.h"
    #include <math.h>
    
    //#using <mscorlib.dll>
    
    //using namespace System;
    
    void display_statement (double, double, double, double, int, double);
    
    
    
    int _tmain()
    
    {
    double a=1;
    double b=1;
    double c=1;
    double d=1;
    double e=1;
    double x=1;
    double i;                     // Interest_Rate Monthly
    double p;                     // Principal
    int n  ;                      // Number Payments
    double Payment_Amount;
    double payment;
    double Total_Amount;
    double total_amount;
    double Tamount_paid;
    double total_interest;
    double Tinterest_paid(double, int);
    double payment_amount (double, double, int);
    
    
    	printf("Please Enter Interest Rate ");            // Key As n.n
    		scanf("%lf",&i);
    	printf("Please Enter Loan Amount ");              // Amount of Loan
    		scanf("%lf",&p);
    	printf("Please Number Of Monthly payments ");     // Number Of Monthly 
    		scanf("%d",&n);
    
    	payment = Payment_Amount (i,p,n);
        Total_Amount = Tamount_paid(payment,n);
        total_interest=Tinterest_paid(total_amount,p);
    
    void display_statement (double, double, double, double, int, double);
    
    }
    
    {
    	double x;
    
    	x = Tinterest_paid(200000, 150000);
    	printf("The result is\n\n %f', X);
    
    		return 0;
    
    
    
    }
    
    double Tinterest_paid (double amount_paid, double Principal)
    
    {
    
    	double int_paid;
    
    	int_paid = amount_paid - Principal;
    
    	return (int_paid);
    
    {
    
    	double x;
    	x = Payment_Amount(5.5, 100000, 60);
    
    }
    
    double Payment_Amount (double Interest_Rate, double Principle, int Number_Payments)
    
    {
    	double a, payment;
    
    	a = Interest_Rate/100;
    	a= a/12;
    
    	payment = (a* Principle)/ (1 - pow((1+a), -Number_Payments));
    	return(payment);
    }
    
    {
    	display_statement (a, b, c, d, x, e);
    	return 0;
    
    }
    
    void display_statement (double payment, double loan_payment, double Tinterest, double Principal, int Number_Payments, double interestrate)
    
    {
    
    	printf("Monthy Payment: $%.2f\n\n", payment);
    	printf("Total Loan Amount; $%.2f\n\n", loan_Amount);
    	printf("Total Interest Payment: $%.2f\n\n", Tinterest);
    	printf("Principal: $%.2f\n\n", Principal);
    	printf("Number Of Payments: %d\n\n", Number_Payments);
    	printf("Interest Rate %.3f percent\n\n", interestrate);
    
    }

  11. #11
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    520
    In ANSI C you have a main function, which is the first function that is called when your program is ran.
    Code:
    int main(void)
    {
      return 0;
    }
    Is how you properly define the main function for C. What're you doing is some kind of weird c++/c/c# mixture, if this is what you want I'm afraid you'll need to find another forum.

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Ok I fix the main. Now what needs to be done, the errors are getting lest. Thank you for the help you have been giveing me.

    Here is the way the code is now.

    Code:
    #include "stdafx.h"
    #include <math.h>
    
    //#using <mscorlib.dll>
    
    //using namespace System;
    
    void display_statement (double, double, double, double, int, double);
    
    
    
    int main(void)
    
    {
    double a=1;
    double b=1;
    double c=1;
    double d=1;
    double e=1;
    double x=1;
    double i;                     // Interest_Rate Monthly
    double p;                     // Principal
    int n  ;                      // Number Payments
    double Payment_Amount;
    double payment;
    double Total_Amount;
    double total_amount;
    double Tamount_paid;
    double total_interest;
    double Tinterest_paid(double, int);
    double payment_amount (double, double, int);
    
    
    	printf("Please Enter Interest Rate ");            // Key As n.n
    		scanf("%lf",&i);
    	printf("Please Enter Loan Amount ");              // Amount of Loan
    		scanf("%lf",&p);
    	printf("Please Number Of Monthly payments ");     // Number Of Monthly 
    		scanf("%d",&n);
    
    	payment = Payment_Amount (i,p,n);
        Total_Amount = Tamount_paid(payment,n);
        total_interest=Tinterest_paid(total_amount,p);
    
    void display_statement (double, double, double, double, int, double);
    
    }
    
    {
    	double x;
    
    	x = Tinterest_paid(200000, 150000);
    	printf("The result is\n\n %f', X);
    
    		return 0;
    
    
    
    }
    
    double Tinterest_paid (double amount_paid, double Principal)
    
    {
    
    	double int_paid;
    
    	int_paid = amount_paid - Principal;
    
    	return (int_paid);
    
    {
    
    	double x;
    	x = Payment_Amount(5.5, 100000, 60);
    
    }
    
    double Payment_Amount (double Interest_Rate, double Principle, int Number_Payments)
    
    {
    	double a, payment;
    
    	a = Interest_Rate/100;
    	a= a/12;
    
    	payment = (a* Principle)/ (1 - pow((1+a), -Number_Payments));
    	return(payment);
    }
    
    {
    	display_statement (a, b, c, d, x, e);
    	return 0;
    
    }
    
    void display_statement (double payment, double loan_payment, double Tinterest, double Principal, int Number_Payments, double interestrate)
    
    {
    
    	printf("Monthy Payment: $%.2f\n\n", payment);
    	printf("Total Loan Amount; $%.2f\n\n", loan_Amount);
    	printf("Total Interest Payment: $%.2f\n\n", Tinterest);
    	printf("Principal: $%.2f\n\n", Principal);
    	printf("Number Of Payments: %d\n\n", Number_Payments);
    	printf("Interest Rate %.3f percent\n\n", interestrate);
    
    }

  13. #13
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    _tmain() is a valid entry point for a Windows application.

  14. #14
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    So are you saying that the way I had the main was allright?

  15. #15
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,257
    Well int main(void) is the standard entry point to an application, but Windows allows programmers to use _tmain() as an entry point so that the command line parameters are passed in the form of TCHARs instead of chars. This allows your application to be unicode compliant which is useful if the application is going to be in a language other than english.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21