My code is not presented correctly in the question. I have copied it from Gedit and pasted it in the text editor. When I posted it and saw the answer, I realised that some of my code was missing and other parts had been changed. I have now tried to edit my question and just type my code instead of pasting it, but still the same thing happens. The >= is being changed into just and = sign. and also other code in the 'if' statement has been removed. Can anyone please help me with this? If I cannot present my code properly, I will never get the right help with my Greedy issue.
This was my original question:
I have been working on Greedy for over a week and still stuck on the same element: When change is .80 only 3 coins are counted. I have written the code in several different ways and used a lot of the discussion feedback from other users but still got nowhere. Please give me advise on my work so I can improve my code to make it work properly. Thanks, Tessa
The outcome is 3 coins after every 'if' or 'else' statement. I believe only the quarters are being counted and not the dimes, nickels and pennies.
#include #include #include int main (void) { int cents = 0; float change; do { printf("How much change is owed?: "); change = GetFloat(); } while (change = 25) { do { cents = cents - (coins * 25); coins += cents / 25; } while (cents >= 25); } else if (cents = 10) { do { cents = cents % 10; coins += cents / 10; } while (cents = 10); } else if (cents = 5) { do { cents = cents % 5; coins += cents / 5; } while (cents = 5); } else (cents = 1) { do { cents = cents % 1; coins += cents / 1; } while (cents 1); } } while (cents > 0); printf("I was greedy and only used %d coins\n", coins); }