CS50x Cash

Photo by Chris Briggs on Unsplash
cd ~/pset1
mkdir cash
cd cash
touch cash.c
open cash.c
// Prompt user for a change value
// Make sure it's positive
// Round it and store as cents in a variable
// Count the least amount of coins needed for the change
// Print result
#include <stdio.h>
#include <math.h>
#include <cs50.h>
int main(void)
{

}
float getValue(void)
{
float change;
do
{
change = get_float("Change owed: ");
}
while (change < 0.00);
return change;
}
float getValue(void);
int coins(int cents);
float owed = getValue();
int cents = round(owed * 100);
make cash
$ ./cash
Change owed: -0.41
Change owed: foo
Change owed: 0.41
int coins(int cents)
{
int count = 0;

while (cents > 0)
{
if (cents >= 25)
{
cents -= 25;
count++;
}
else if (cents >= 10)
{
cents -= 10;
count++;
}
else if (cents >= 5)
{
cents -= 5;
count++;
}
else
{
cents -= 1;
count++;
}
}
return count;
printf("%d\n", coins(cents));
~/pset1/cash/ $ style50 cash.c
Results generated by style50 v2.7.4
Looks good!
~/pset1/cash/ $ check50 cs50/problems/2020/x/cash
...
Results for cs50/problems/2020/x/cash generated by check50 v3.1.2
:) cash.c exists
:) cash.c compiles
:) input of 0.41 yields output of 4
:) input of 0.01 yields output of 1
:) input of 0.15 yields output of 2
:) input of 1.6 yields output of 7
:) input of 23 yields output of 92
:) input of 4.2 yields output of 18
:) rejects a negative input like -1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""