Hi everyone, I have decided to start a course on programming called CS50, and one of the tasks Im asked to do is program in gedit using C, a simple program that asks for the change owed to the customer and then gives back the number of coins needed to satisfy said change. Nevertheless, the cashier is greedy, and likes to have many coins, so he has to give the bigger amount coins first, starting with 0.25, then 0.10 then 0.05 and then 0.01.
For example, if I input that the change owed is 0.41, the program must return a value of 3 coins, a 0.25, a 0.05 and a 0.01.
I have written the following:
insertCode:#include <stdio.h> #include <cs50.h> int main(void) { float change; int coins; coins = 0; printf("How much change is owed\n"); change = GetFloat(); for (;change>0.00;) { if (change>=0.25) { change-=0.25; coins+=1; } else if (change>=0.10 && change<0.25) { change-=0.10; coins+=1; } else if (change>=0.05 && change<0.10) { change-=0.05; coins+=1; } else if (change>=0.01 && change<0.05) { change-=0.01; coins+=1; } } printf("%d\n",coins); }
But for some reason it is answering to the numbers divisible by 0.25, as soon as i say 0.41, or 0.01 it just jumps a line and does nothing.
Please help me solve this problem not by offering me a better code completely, but by working from this code. Thanks in advance
I really am new to this so please bear with my negligence xD