Here is the final version of the pSet1 Cash problem. I couldn’t work out how to use the % operator. I may come back to revise the problem if in the future it becomes clearer.
#include <cs50.h> #include <stdio.h> #include <math.h> int main (void) { float input; int cents; int coins; //Prompt user for an amount of change do { input = get_float("How much change: "); } while (input < 0); cents = input * 100; printf("%0.2i\n", cents); coins = 0; while (cents >= 25) { cents = cents - 25; coins ++; } while (cents >= 10) { cents = cents - 10; coins ++; } while (cents >= 5) { cents = cents - 5; coins ++; } while (cents >= 1) { cents = cents - 1; coins ++; } printf ("%i\n", coins); }
The final results prints as follows:
How much change: .75 75 3