Hey there i was wondering if someone can help me with my program. I thought i had it down...but i'm having some problems. Here's the assignment.
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() three 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 variables.
Third Call--ask for a total value input from the keyboard and on return print the contents of the variables.
Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies
and not:
TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies
Here's my code:
I'm getting a slew of errors once i compile. if anyone can help it would be greatly appreciated. Thanks for your time :)
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() three 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 variables.
Third Call--ask for a total value input from the keyboard and on return print the contents of the variables.
Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies
and not:
TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies
Here's my code:
Code:
#include <stdio.h> int main() { void change (float); float value; int count, i; printf("Enter the value you wish to count: "); scanf("%d", count); for (i = 0, i <= count, i++) { printf("Please enter the amount: "); scanf("%f", value); } return 0; } void change (float x) int quarters, dimes, nickles, pennies; float value, store; value = x; store = x; while (value >= .25) { quarters ++; value = value - .25; } while (value >= .1) { dines ++; value = value - .1: } while (value >= .05) { nickels ++; value = value - .05; } while (value >= .01) { pennies ++; value = value - .01; } printf("The total value entered was: %f ", store); printf("%d" quarters, quarters\n); printf("%d" dimes, dimes\n); printf("%d" nickles, nickles\n); printf("%d" pennies, pennies\n); }
Comment