Last active
December 31, 2022 11:52
-
-
Save teeschorle/9d5e60c7d6d173429c33ca53137d14e7 to your computer and use it in GitHub Desktop.
CS50 Problem Set 1 (Fall 2019) - Cash
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
//CS50 Problem Set 1 (Fall 2019): Cash | |
//Author: teeschorle | |
#include <cs50.h> | |
#include <stdio.h> | |
#include <math.h> | |
int main(void) | |
{ | |
float change; | |
do | |
{ | |
change = get_float("Change owed: "); | |
} | |
while (change < 0); | |
//convert change to int | |
int coins = round(change * 100); | |
//find out how many of each coin | |
int counter = 0; | |
while (coins > 24) | |
{ | |
coins = coins - 25; | |
counter ++; | |
} | |
while (coins > 9) | |
{ | |
coins = coins - 10; | |
counter ++; | |
} | |
while (coins > 4) | |
{ | |
coins = coins - 5; | |
counter ++; | |
} | |
counter = counter + coins; | |
printf("%i\n", counter); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment