Skip to content

Instantly share code, notes, and snippets.

@wise-introvert
Last active September 24, 2021 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wise-introvert/91ab8585ad6fa2e301550b57c4b60bcf to your computer and use it in GitHub Desktop.
Save wise-introvert/91ab8585ad6fa2e301550b57c4b60bcf to your computer and use it in GitHub Desktop.
Week 2 Part 1
/*
* AUTHOR <your name>
* EMAIL <your seneca email id>
* SENECA ID <your seneca id>
* DESCRIPTION Print message to the screen
*/
#include<stdio.h>
#include<math.h>
int main(void) {
float amount;
printf("Change Maker Machine\n");
printf("====================\n");
printf("Enter dollars and cents amount to convert to coins: $");
scanf("%f", & amount);
double coins[3] = {
2,
1,
0.25,
};
char * names[3] = {
"Toonies",
"Loonies",
"Quarters",
};
double remaining = amount;
for (int i = 0; i < 3; i++) {
double currentCurrency = coins[i];
int quantity = remaining / currentCurrency;
remaining = remaining - (quantity * currentCurrency);
if(currentCurrency == 2) {
printf("\n$%.2lf %s X %d (remaining: $%.2lf)", currentCurrency, names[i], quantity, remaining);
} else {
printf("\n$%.2lf %s X %d (remaining: $%.2lf)", currentCurrency, names[i], quantity, remaining);
}
}
if(remaining > (float) 0) {
printf("\n\nMachine error! Thank you for letting me keep $%.2f!\n", remaining);
} else {
printf("\n\nAll coins dispensed!\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment