Having trouble getting the right output out of this assignment.
The first assignment is:
Write a C function named change() that accepts a floating point number of total coins and the addresses of the integer variables named quarters, dimes, nickels, and pennies. The function should determine the number of quarters, dimes, nickels and pennies in the total coins number passed to it and write these values directly into the respective variables declared in its calling function using pointers.
Call the function change() from main() 3 times and print out the contents of the variables quarters, dimes, nickels, and pennies after each function return.
First call - pass in the total value $1.88 and on return print the contents of the variables.
second call - pass in the total value .32 and on return print the contents of the variable
Thrid call - ask for a total value input from the keyboard and on return print the contents of the variable.
Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies
This is what i have so far:
Code:
#include <stdio.h>
void change(float, int *, int*, int*, int*);
int main()
{
float total;
int quarters, dimes, nickels, pennies;
{
total = 1.88;
change(total, &quarters, &dimes, &nickels, &pennies);
printf("TOTAL VALUE ENTERED: %6.2f", total);
printf("%d quarters", quarters);
printf("%3d dimes", dimes);
printf("%3d nickels", nickels);
printf("%3d pennies", pennies);
}
{
total = 0.32;
change(total, &quarters, &dimes, &nickels, &pennies);
printf("TOTAL VALUE ENTERED: %6.2f", total);
printf("%d quarters", quarters);
printf("%3d dimes", dimes);
printf("%3d nickels", nickels);
printf("%3d pennies", pennies);
}
{
printf("Enter the amount of money in your pocket: \n");
scanf("%f", &total);
change(total, &quarters, &dimes, &nickels, &pennies);
printf("TOTAL VALUE ENTERED: %6.2f", total);
printf("%d quarters", quarters);
printf("%3d dimes", dimes);
printf("%3d nickels", nickels);
printf("%3d pennies", pennies);
}
return 0;
}
void change(float total, int *quarters, int *dimes, int *nickels, int *pennies)
{
if( total >= 0.25 )
*quarters = (total/0.25);
if( total >= 0.10 )
*dimes = (total - (*quarters * 0.25))/0.10;
if( total >= 0.05 )
*nickels = (total - (*quarters * 0.25) - (*dimes * 0.10))/0.05;
if( total < 0.05 )
*pennies = (total - (*quarters * 0.25) - (*dimes * 0.10) - (*nickels * 0.05))/0.01);
return;
}
c:\program files\miracle c\change.c: line 51: cannot convert from float/double '*quarters = (total/0.25)' aborting compile
This is what I keep getting so I think I just have to fiqure out how to change quarters, dimes, nickels and pennies to an integer but I'm not quite sure how to do it. Any help would be greatly appreciated.