Name:
Anonymous
2010-11-24 12:17
can you help create a program that will accept an amount and output its denomination.
example
amount: 5670.45
1000: 5
500: 6
200: 0
100: 6
50: 1
20: 1
10: 0
.25: 1
.05: 3
Name:
Anonymous
2010-11-24 17:54
>>2
What kind of moron uses "double" to represent currency? And then subtracts values in a loop? Did your brain fry from writing too much ECMAScript?
$ cat test.c
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
double x = strtod(argv[1], 0);
while (x >= 0.05) x -= 0.05;
printf("x = %f\n", x);
return 0;
}
$ gcc test.c ; ./a.out 0.15
x = 0.050000
Note how "x = 0.05000", and yet "x >= 0.05" is false? Need I connect the dots, from A to B to C as for a little child?