Thread: need help calling a function, please.

  1. #46
    Registered User Ashl7's Avatar
    Join Date
    Oct 2012
    Posts
    57
    Quote Originally Posted by Matticus View Post
    Thanks anduril!

    @rosemary, if you're really interested in learning and not just getting a good grade somewhere, I'd recommend you play around with some small, simple programs using functions to get the hang of it. The code I provided in post #4 is a fully working program (though with no output). That might help you see how all the details of a function works. Then mix up the code a bit, seeing if you can make another function that does multiplication of two numbers, etc. Writing several small, simple programs exercising concepts you're learning will give you a great understanding of those concepts. Then you can scale up the programs to deal with more [relatively] complicated functions as you're doing now.
    Matticus thanks for linking me to here man...I know a lot more about functions now...I can easily make one! thx bro(or sis!)

  2. #47
    Registered User
    Join Date
    Sep 2012
    Posts
    99
    I'm getting a better understanding. This is one way of doing it-
    Code:
    #include <stdio.h>
    
    
    	int pennies=0, nickels=0, dimes=0, quarters=0, p,n,d,q;
    	float x=0;
    
    
    int insert(int p, int n, int d, int q)
    {
    	printf("insert\n");
        scanf("%d%d%d%d", &p, &n, &d, &q);
        pennies += p;
        nickels += n;
        dimes += d;
        quarters += q;	
    }
    int remove(int p, int n, int d, int q)
    {
    	printf("remove\n");
        scanf("%d%d%d%d", &p, &n, &d, &q);
        pennies -= p;
        nickels -= n;
        dimes -= d;
        quarters -= q;
    }
    float dollars()
    {
    	x = pennies + 5*nickels + 10*dimes + 25*quarters;
        x = (float)x/100;
    }
    void display()
    {
    	printf("%d quarters + %d dimes + %d nickels + %d pennies = $%.2f \n", quarters, dimes, nickels, pennies, x);
    }
    int main(void)
    {
    	display();
    	
    	insert(p,n,d,q);
    	dollars();
    	display();
    	
    	remove(p,n,d,q);
    	dollars();
    	display();
    	
    return 0;
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-26-2011, 04:44 AM
  2. Calling a function inside a function
    By kizyle502 in forum C Programming
    Replies: 1
    Last Post: 09-17-2009, 11:29 AM
  3. Replies: 15
    Last Post: 06-09-2009, 02:19 AM
  4. Calling Cdocument function in Cview function
    By RancidWannaRiot in forum Windows Programming
    Replies: 5
    Last Post: 09-22-2005, 12:09 PM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM