Functions

This is a discussion on Functions within the C Programming forums, part of the General Programming Boards category; Recently in my C class we learned about functions and pass by reference and I have a question about a ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    32

    Functions

    Recently in my C class we learned about functions and pass by reference and I have a question about a function in my programming assignment.

    Code:
    //Pre-conditions: numchips > 0.
    //Post-conditions: Returns the cash obtained for selling
    //                 numchips number of chips.
    int sellchips(int *numchips_ptr)	{
    
    	int chips_sell;
    	int money_sell;
    	int cash_pst_sell;
    	
    	printf("How many chips do you want to sell?\n");
    	scanf("%d", &chips_sell);
    	
    	if	(*numchips_ptr > 0 && *numchips_ptr >= chips_sell)	{
    		*numchips_ptr = *numchips_ptr - chips_sell;
    		money_sell = chips_sell * SELL_VALUE;
    		printf("$%d\n", money_sell);
    	}
    	else	{
    		printf("Sorry, you do not have that many chips. No chips sold.\n");
    	}
    }
    it updates the number of chips in my main fine but I'm having trouble initializing another pointer for the amount of cash the user has so i can manipulate that value.
    additionally, i have the amount, money_sell, that i'm supposed to add on to cash...
    i've tried multiple attempts at initializing another function with a pointer towards cash then calling it in the above function but i'm not sure how that's supposed to work out.

    any help would be greatly appreciated

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    int sellchips(int * numchips_ptr,int * cash_ptr);
    *cash_ptr +=moneysell;

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    32
    haha, thats embarassing

    i knew it was something silly

    thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 06:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM

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