-
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..:)
-
Re: need help on pointer
Quote:
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.
-
change can't be both a double, and a function