Last active
September 24, 2021 23:22
-
-
Save wise-introvert/685cf312fc0071a86b681296bd365d95 to your computer and use it in GitHub Desktop.
Week 2 Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 serviceFee = amount * 0.05; | |
printf("Service fee (5.0 percent): $%.2lf\nBalance to dispense: $%.2lf\n\n", serviceFee, amount - serviceFee); | |
double coins[6] = {2, 1, 0.25, 0.10, 0.05, 0.01}; | |
char *names[6] = {"Toonies", "Loonies", "Quarters", "Dimes", "Nickles", "Cents"}; | |
double remaining = amount - serviceFee; | |
for (int i = 0; i < 6; i++) { | |
double currentCurrency = coins[i]; | |
int quantity = remaining / currentCurrency; | |
remaining = remaining - (currentCurrency * quantity); | |
printf("\n$%.2lf %s x %d (remaining: $%.2lf)", currentCurrency, names[i], quantity, remaining); | |
} | |
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