Thread: Easy beginner's question about pointers

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    Easy beginner's question about pointers

    Hello everyone, so I'm in an intro to programming in C class and have a homework assignment due. It's almost done and pretty awesome except for one function that is giving me a problem. It looks like this:
    Code:
    //uses MoneyMenu function to display and collect dollar amounts from the user 
    //uses CheckMoney function to keep comparing the added deposited amount to the item cost.
    void GetMoney(double *bank, double item_cost, char selection)
    {
    	MoneyMenu(&bank, item_cost);	
    	CheckMoney(bank, item_cost);
    }
    I don't understand how CheckMoney can call on the parameter bank, when GetMoney doesn't contain the information for bank, it uses the pointer *bank. When I try to do the above, my complier sticks it's tongue out at me and goes pbbbbbbbbbt. The tricky part is that the parameters for all the functions here HAVE to stay the same. They were assigned by the professor. So is there something I'm not getting, or is this a typo on the professor's behalf. (I've already emailed asking but in true fashion, he's taking his time getting back to me). Thanks!

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    I'll bet your compiler gives a more detailed diagnostic than that.

    It's very, very, very hard to figure out what's going wrong with your code when you show neither the prototype for the function giving you the problem nor the actual error message itself.

    Also, what do you mean "call on the parameter bank"? If you mean just using "bank" instead of "*bank", there's nothing wrong with that: "bank" is a pointer, "*bank" is a double.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    3
    The prototypes are these:
    Code:
    //uses MoneyMenu function to display and collect dollar amounts from the user 
    //uses CheckMoney function to keep comparing the added deposited amount to the item cost.
    void GetMoney(double *bank, double item_cost, char selection);  
    
    //Displays the codes for money input- gets user input amounts 
    //compares the int codes and updates the bank amount entered
    void MoneyMenu(double *bank, double item_cost);
    
    //compares the amount the user has in the bank to the price of item selected. 
    //It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
    int CheckMoney(double bank, double item_cost);
    And the errors my complier gives are these:
    Code:
    1>------ Build started: Project: appStore, Configuration: Debug Win32 ------
    1>  appStore.c
    1>c:\documents and settings\kyle\desktop\intro to programming in c\appstore\appstore.c(138): warning C4047: 'function' : 'double *' differs in levels of indirection from 'double **'
    1>c:\documents and settings\kyle\desktop\intro to programming in c\appstore\appstore.c(138): warning C4024: 'MoneyMenu' : different types for formal and actual parameter 1
    1>c:\documents and settings\kyle\desktop\intro to programming in c\appstore\appstore.c(139): error C2440: 'function' : cannot convert from 'double *' to 'double'
    1>c:\documents and settings\kyle\desktop\intro to programming in c\appstore\appstore.c(139): warning C4024: 'CheckMoney' : different types for formal and actual parameter 1
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  4. #4
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    In GetMoney(...) Bank is a pointer to a double, you are trying to use it as if it was a double. Don't do that
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    3
    Thank you guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help for my exam. easy question
    By joker_tony in forum C Programming
    Replies: 4
    Last Post: 04-15-2008, 03:09 PM
  2. Question about pointers
    By TyPR124 in forum C++ Programming
    Replies: 8
    Last Post: 11-12-2007, 11:13 AM
  3. Array pointers question?
    By ben2000 in forum C Programming
    Replies: 4
    Last Post: 07-26-2007, 01:31 AM
  4. Newbie question: pointers, other program's memory
    By xxxxme in forum C++ Programming
    Replies: 23
    Last Post: 11-25-2006, 01:00 PM
  5. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM