Skip to content

Instantly share code, notes, and snippets.

@wise-introvert
Created September 24, 2021 02:21
Show Gist options
  • Save wise-introvert/c8c05bc68579608591a56a86064df68e to your computer and use it in GitHub Desktop.
Save wise-introvert/c8c05bc68579608591a56a86064df68e to your computer and use it in GitHub Desktop.
/*
* AUTHOR <your name>
* EMAIL <your seneca email id>
* SENECA ID <your seneca id>
* DESCRIPTION <description>
*/
#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);
int toonies = amount / 2;
double amountRemainingAfterToonies = amount - ((double) (toonies * 2));
int loonies = ((double) amountRemainingAfterToonies) / 1;
double amountRemainingAfterLoonies = amountRemainingAfterToonies - loonies;
int quarters = ((double) amountRemainingAfterLoonies) / 0.25;
double amountRemainingAfterQuarters = amountRemainingAfterLoonies - ((double) (quarters * 0.25));
if(toonies > 0) {
printf("\n$2.00 Toonies x %d (remaining: $%.2f)", toonies, amountRemainingAfterToonies);
}
if(loonies > 0) {
printf("\n$1.00 Loonies x %d (remaining: $%.2f)", loonies, amountRemainingAfterLoonies);
}
if(quarters > 0) {
printf("\n$0.25 Quarters x %d (remaining: $%.2f)", quarters, amountRemainingAfterQuarters);
}
if(amountRemainingAfterQuarters > 0) {
printf("\n\nMachine error! Thank you for letting me keep $%.2f!", amountRemainingAfterQuarters);
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment