Skip to content

Instantly share code, notes, and snippets.

@aryan348
Created July 16, 2020 15:10
Show Gist options
  • Save aryan348/e556662be1b17eec6b0c08de541be73e to your computer and use it in GitHub Desktop.
Save aryan348/e556662be1b17eec6b0c08de541be73e to your computer and use it in GitHub Desktop.
CS50 Problem Set 2 (Fall 2020) - Readability
#include <math.h>
#include <cs50.h>
#include <stdio.h>
int main(void)
{
float d;
do
{
d = get_float("Change Owed: ");
}
// do while to only accept positive float
while (d <= 0);
// rounding cents to 100 for better convertion
int cents = round(d * 100);
// initializing count to 0
int count = 0;
// for counting greater>=25
while (cents >= 25)
{
count++;
cents = cents - 25;
}
// for counting greater>=10
while (cents >= 10)
{
count++;
cents = cents - 10;
}
// for counting greater>=5
while (cents >= 5)
{
count++;
cents = cents - 5;
}
// for counting greater>=1
while (cents >= 1)
{
count++;
cents = cents - 1;
}
// for priting count
printf("%i\n", count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment