Yes, it should. From my "int main() {" line and on. Let me know if it doesn't.
Edit: If it doesn't, maybe this will:
Code:
#include <stdio.h>
int main() {
// The file
FILE *transactions;
// The numbers
float cost, payment, change;
// The remainder in depth
int penniesInTill = 0, nickelsInTill = 0, dimesInTill = 0, quartersInTill = 0;
int dollarsInTill = 0, fivesInTill = 0, tensInTill = 0, twentiesInTill = 0;
transactions = fopen ("transactions.dat", "r");
if (transactions == NULL) {
printf ("File, transactions, could not be opened\n");
}
fscanf(transactions, "%f\n", &cost);
printf("The cost is %g\n", cost);
fscanf(transactions, "%f\n", &payment);
printf("The customer's payment was %g\n", payment);
change = cost - payment;
printf("The change due is %g\n", change);
while (change >= 20.0f) {
change -= 20.0f;
twentiesInTill++;
}
while (change >= 10.0f) {
change -= 10.0f;
tensInTill++;
}
while (change >= 5.0f) {
change -= 5.0f;
fivesInTill++;
}
while (change >= 1.0f) {
change -= 1.0f;
dollarsInTill++;
}
while (change >= 0.25f) {
change -= 0.25f;
quartersInTill++;
}
while (change >= 0.10f) {
change -= 0.10f;
dimesInTill++;
}
while (change >= 0.05f) {
change -= 0.05f;
nickelsInTill++;
}
while (change >= 0.01f) {
change -= 0.01f;
penniesInTill++;
}
printf("In Detail\n\nTwenties: %d\nTens: %d\nFives: %d\nOnes: %d\nQuarters: %d\nDimes: %d\nNickels: %d\nPennies: %d\n",
twentiesInTill, tensInTill, fivesInTill, dollarsInTill, quartersInTill, dimesInTill, nickelsInTill, penniesInTill);
return 0;
}
- Stack Overflow