Skip to content

Instantly share code, notes, and snippets.

@teeschorle
Last active December 31, 2022 11:52
Show Gist options
  • Save teeschorle/9d5e60c7d6d173429c33ca53137d14e7 to your computer and use it in GitHub Desktop.
Save teeschorle/9d5e60c7d6d173429c33ca53137d14e7 to your computer and use it in GitHub Desktop.
CS50 Problem Set 1 (Fall 2019) - Cash
//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