New to the forum, and was hoping I could get some help. I'm trying to teach myself my university's introduction to computer science class over the summer so I would be better prepared when I take it for real. One of the programs is to apply a "greedy" approach to coin counting. For example:
If I have $0.42, I would realize that it can only contain one quarter, giving me $0.16 left over. That would correlate to one dime with $0.06 left over. That would result in one nickel and two penny resultantly. The output of the program would be "5," representing the least amount of coins possible to make $0.42.
So, here is the portion of my attempt that didn't work
Code:
// analyzes user input
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
if (change2 >= 25)
do
{
quarters = change2 / 25;
change2 = change2 % 25;
}
while (change2 >= 25);
if (change2 < 25 || change2 >= 10)
do
{
dimes = change2 / 10;
change2 = change2 % 10;
}
while (change2 < 25 || change2 >= 10);
int total = quarters + dimes + nickels + pennies;
printf("%d\n", total);
printf("%d\n", change2);
}
I have only included the first two steps, because that's where the program begins to break down. The first section with quarters works fine. The problem is getting the data to transfer to the section on dimes. It just seems not to work. Even when I isolate the dime section, the second "if," it produces nothing. There should be no syntax errors involved.
Thanks so much!