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

The question itself is confusing to me... create a function that accepts floating point numbers and first call, second call and third call... I am not sure on how to go about this

08-05-2011

AndrewHunter

Quote:

Originally Posted by ARod609

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.

This is telling you what your function prototype should look like. The function should take 5 arguments, a float (for total coin amount), and 4 pointers to integers (for quarters, dimes, nickels, and pennies).

Quote:

Originally Posted by ARod609

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.

This tells you what the function should do and how it should do it.

Quote:

Originally Posted by ARod609

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.

This is telling you how to lay out your program, e.g. what your main should look like. Not worded the best, however they want you to make a program that looks something like:

A hint for this: most banking software actually stores the amount in a large integer of pennies. So if I were to do something like this I would take the total input and convert it to pennies before I started, e.g. 1.10 would become 110 pennies. After that the operations become pretty simple. Look at what '/' does and what '%' does for math operations.

08-06-2011

CommonTater

Quote:

Originally Posted by ARod609

1) Math header not sure if i need it...
2) Function I am not sure on how to use it correctly...
3) Output did exactly what I was not supposed to do...

No offense is intended... but, I'm betting you went straight from reading the assignment to your keyboard and started tapping out code... hence, failure.

Every program, no matter how small, involves the 4 steps in my signature...
1) Analyse the problem until you have a good understanding of what is required.
2) Then and only then, begin planning a solution to the problem... researching as required.
3) Now that you know what your writing... you can sit down and create code.
4) Once the code is in a state where it's at least partially functional you should begin testing.

But take hope... Thomas Edison, inventor of the lightbulb was once in a position to say: "No. I don't know how to make a lightbulb but I have discovered several ways not to make one." (Or very close) ... You are now in the forunate position of having disovered one of a great many ways not to write a computer program.

08-06-2011

stahta01

@ARod609:

Your problem is to write a function on how to make change; your function does NOT do that.
Do you know how to make change?
If not, find someone to tell you how to do it.

Then think about it and write down the steps to do it.
Change the steps into a C program.

Quote:

TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies

The above coins add up to 1.88 you answer does NOT add up to the value inputted.

Tim S.

08-06-2011

ARod609

@Stahta01 I know I just dont know how to apply it in "C" lol... so I am lost using the call functions with the modular division (%) to get the remainder to break it down in cents. I thought it would be hot to be able to enter any number and get back the change...

08-06-2011

stahta01

Quote:

Originally Posted by ARod609

@Stahta01 I know I just dont know how to apply it in "C" lol... so I am lost using the call functions with the modular division (%) to get the remainder to break it down in cents. I thought it would be hot to be able to enter any number and get back the change...

You C code implies you have no idea on how to make change!

We are not a place that writes code for others; try to do some work.
Write out the steps; post the steps.

Tim S.

08-06-2011

ARod609

@Stahta01
I am just trying to learn "C" with the help of the board, I only post a question when I am stumped... Your jokes are funny haha, now I appreciate your advice on writing out the steps and thank you. Everything else is really un called for!

08-06-2011

CommonTater

Quote:

Originally Posted by ARod609

@Stahta01 I know I just dont know how to apply it in "C" lol... so I am lost using the call functions with the modular division (%) to get the remainder to break it down in cents. I thought it would be hot to be able to enter any number and get back the change...

Screw the code... think about the problem... How does making change work?

Lets say you owe someone $0.41 in change...
How much of that can you make up in quarters? (1)
Ok, so you give them a quarter.
How much do you still owe them? ($0.16)
How much of that amount can you make up in dimes? (1)
Ok so you give them a dime.
How much do you still owe them? ($0.06)
How much of that can you make up in nickles? (1)
Give them a nickel, how much is left? ($0.01)
So you give them a penny....

See the problem is you're trying to think about C code, when you haven't even understood the problem itself...

08-06-2011

CommonTater

Quote:

Originally Posted by ARod609

@Stahta01
I am just trying to learn "C" with the help of the board, I only post a question when I am stumped... Your jokes are funny haha, now I appreciate your advice on writing out the steps and thank you. Everything else is really un called for!

You need to stop defending yourself from your friends and start listening to their advice...