c pointer with function and money -
write program dispense change. user enters amount paid , amount due. program determines how many dollars, quarters, dimes, nickels, , pennies should given change. ask user 2 inputs (amount due , amount paid) in main() , send these along pointers 5 parameters (dollars, quarters, dimes, nickels, pennies) function called change(), calculate number of each give out. print results main().
what wrong program now. compiles no problems answer wrong wrong.
#include <stdio.h> #include <conio.h> //function prototype void change( int *d, int *q, int *di, int *n, int *p, int paid, int due ); int main() { //variables int paid; int due; int dollars; int quarters; int dimes; int nickels; int pennies; //reference variables int *d; int *q; int *di; int *n; int *p; printf( "enter amount due: \n" ); scanf( "%d", &due ); printf( "enter amount paid: \n" ); scanf( "%d", &paid ); change( &dollars, &quarters, &dimes, &nickels, &pennies, paid, due ); printf( "dollars = %d\nquarters = %d\ndimes =%d\nnickels = %d\npennies = %d", dollars, quarters, dimes, nickels, pennies ); getch(); return 0; } void change( int *d, int *q, int *di, int *n, int *p, int paid, int due ) { int dm; int qm; int dim; int nm; int pm; int modu; int modu2; int modu3; int total; int penniestotal; total = due - paid; penniestotal = total * 100; dm = penniestotal / 100; modu = penniestotal % 100; qm = modu / 25; modu2 = modu % 25; dim = modu2 / 10; modu3 = modu2 % 10; nm = modu3 / 5; pm = modu3 % 5; }
you declare/define function as
void change(int *d,int *q,int *di, int *n, int *p, int paid, int due )
and call as
change(paid,due,&dollars,&quarters,&dimes,&nickels,&pennies);
the first 2 params paid
, due
passed integers while function expects integer pointers.
seems want pass them last , second last parameters.
Comments
Post a Comment