# Greedy P set Works?

When I input .41 in outputs 4 but when I input lets say 23, it gives me a crazy number, and glitches out

Code:

``````/**
* greedy.c
*
* My name
*
* Give the least number of coins needed to pay
*/

#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <ctype.h>

int main(void)
{
float b;
do
// prompts the user for an input
{
printf("Hello, how much change is owed?: ");
b = GetFloat();
}
while(b<0);

int q = 25;
int d = 10;
int n = 5;
int p = 1;
int x;
int count = 0;

int balance = round(b*100);
printf("%i\n", balance);
// substracts quarters from balance
do
{
x = balance/q;
count = count + x;
balance = balance - (q*x);
}
while(b >= q);

// substracts dimes from balance
do
{
x = balance/d;
count = count + x;
balance = balance - (d*x);
}
while (b >= d);

// substracts nickles from balance
do
{
x = balance/n;
count = count + x;
balance = balance - (n*x);
}
while (b >= n);

// substracts pennies from balance
do
{
x = balance/p;
count = count + x;
balance = balance - (p*x);
}
while (b >= p);

//prints out outcome
{
printf("The least number of coins needed is: %i\n" , count);
printf("The bal after coins paid is: %i\n", balance);
}
}
``````