**I've done a few changes and i'd just like to know if you can help me find out why it isn't running. When I run it the text is printed but the input never stops running. ** The program is meant to replicate(?) the greedy algorithm. It first asks the user how much change is owed and then provides the minimum number of coins with which said change can be made.
I'd greatly appreciate any help you can give with my code.
#include <stdio.h>
#include <math.h>
int main(void)
{
//declared variables
float change;
int num = 0;
// prompts for amount owed
printf("Please provide the amount owed: ");
change = GetFloat();
while (change != 0)
change = change * 100;
int owed = round(change);
{
// if statements for calculating number of coins required
if (owed >= 25)
{
owed = owed - 25;
num ++;
}
if (owed >= 10 && owed < 25)
{
owed = owed - 10;
num ++;
}
if (owed >= 5 && owed < 10)
{
owed = owed - 5;
num ++;
}
if (owed >= 1 && owed < 5)
{
owed = owed - 1;
num ++;
}
}
printf("%d\n", num);
}
When I alter the while statement and comment out the 'change = change * 100;' it starts to work. However, in doing so the round function won't execute.
change = GetFloat() * 100;
while (change != 0)
// change = change * 1000;
// int owed = round(change);