This is a discussion on Change function within the C Programming forums, part of the General Programming Boards category; Originally Posted by mjpam It's not necessarily overcomplicated if he has to use a function to calculate the change. In ...
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
If I understand what is being done correctly, you pass the pointers to the variables to the function and modify the values of the variables pointed to be the pointers in the function.
I think the value of pennies gets messed up through all the type conversions, and it may be a rounding issue. I got some results by adding 0.5 to the pennies and casting it as an integer.