Created
March 8, 2019 04:25
-
-
Save Edmundworks/51d7b97885cb392dcbdbde2e8e785568 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <cs50.h> | |
#include <stdio.h> | |
#include <math.h> | |
//notes to self, it works for entering numbers as pennies ie 85 for $0.85 | |
//need to take input as float and convert to int | |
//need to prompt user again if input is negative or not a number | |
//need to remove printf of each coin so output is just total | |
int main(void) | |
{ | |
int change = get_int("Change owed: "); | |
int quarter_count = 0; | |
int nickel_count = 0; | |
int dime_count = 0; | |
int penny_count = 0; | |
int total = 0; | |
quarter_count = ((change - (change % 25)) / 25); | |
nickel_count = (change % 25) / 10; | |
dime_count = ((change % 25) % 10) / 5; | |
penny_count = (((change % 25) % 10) % 5); | |
total = (quarter_count + nickel_count + dime_count + penny_count); | |
printf("%i quarters\n", quarter_count); | |
printf("%i nickels\n", nickel_count); | |
printf("%i dimes\n", dime_count); | |
printf("%i pennies\n", penny_count); | |
printf("%i \n", total); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment