Thread: need help on pointer

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    need help on pointer

    i'm suppose to write a program using pointer to dispense change. The user the amount paid and the amount due. The program determines how many dollars, quarters, dimes, nickels, and pennies should be given as change. Write a function with five output parameters that determine the quantity of each kind of coin.
    Here is what i've written so far...can anyone please help me...thanks for your time and your helps are appreciated it....
    Code:
    #include <stdio.h>
    
    void change (double amt_paid1, 
    			 double amt_due1, 
    			 int dol, 
    			 int quar, 
    			 int dim, 
    			 int nick, 
    			 int pen);
    
    int main (void)
    
    {
    
    	double amt_paid, amt_due;
    	int dollars, quarters, dimes, nickels, pennies;
    
    	printf("Enter the amound paid: ");
    	scanf("%d", &amt_paid);
    	printf("Enter the amound due: ");
    	scanf("%d", &amt_due);
    
    	change(amt_paid, amt_due, &dollars, &quarters, &dimes, &nickels, &pennies);
    
    	printf("Your change are: %d dollars, %d quarters, %d dimes, %d nickels, and %d pennies", 
    		dollars, quarters, dimes, nickels, pennies);
    
    	
    	return (0);
    }
    
    
    void change (double amt_paid1, 
    			 double amt_due1, 
    			 int *dol, 
    			 int *quar, 
    			 int *dim, 
    			 int *nick, 
    			 int *pen)
    {
    
    	double temp_amt;
    	temp_amt = (amt_due1 - amt_paid1) * 100.0;
    	*dol = (int) temp_amt / 100;
    	*quar = (int) (temp_amt - (*dol * 100)) / 25;
    	*dim = (int) (temp_amt - (*dol * 100) - (*quar * 25)) / 10;
    	*nick = (int) (temp_amt - (*dol * 100) - (*quar * 25) - (*dim * 10)) / 5;
    	*pen = (int) (temp_amt - (*dol * 100) - (*quar * 25) - (*dim * 10) - (*nick * 5)) / 1;
    }
    ok...i changed the one in bold type....but now i got this error "'change' : cannot convert parameter 3 from 'int *' to 'int'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast".....

    Again, thanks for the fast response guys..
    Last edited by kylix; 10-28-2002 at 10:11 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: need help on pointer

    Originally posted by kylix
    Code:
    void change (double amt_paid, 
    			 double amt_due, 
    			 int dollars, 
    			 int quarters, 
    			 int dimes, 
    			 int nickels, 
    			 int pennies);
    
    void change (double amt_paid, 
    			 double amt_due, 
    			 int *dollars, 
    			 int *quarters, 
    			 int *dimes, 
    			 int *nickels, 
    			 int *pennies)
    See the problem? The first is your prototype. The second is the actual function.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    change can't be both a double, and a function
    Demonographic rhinology is not the only possible outcome, but why take the chance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM