I have wrote some code to calculate what type and amount of bills to be returned to the customer given their amount owed and amount paid. The implementation of change() is in another file (change.c).
#include <stdio.h>
#include "change.h"
int main() {
double bill, pay;
char temp;
temp = getchar();
while (temp != EOF){
ungetc(temp, stdin);
scanf("%lf%lf", &bill, &pay);
change(bill, pay);
temp = getchar();
}
return 0;
}
My problem is that when I tried terminate the program with crtl+d, an extra set of output is printed.
3.5 69.1 //input from stdin
Change of:
1 fifty dollar bill
0 twenty dollar bill
7 two dollar coin
15 dime
1 nickel
4 12.4 //input from stdin
Change of:
0 fifty dollar bill
0 twenty dollar bill
4 two dollar coin
4 dime
1 nickel
Change of:
0 fifty dollar bill
0 twenty dollar bill
4 two dollar coin
4 dime
1 nickel
2 inputs but 3 outputs (last output is the same as the second last output). I have spent hours investigating but cannot figure out why. Any help would be greatly appreciated!