Miscellaneous > Programming & Networking

Programming Challenge N

<< < (3/3)

TheQuirk:
The operators / and %.

sledz41:
Therefore the code would be:

--- Code: ---#include
 
int main ()
{
 
int value;
int count = 0;
 
printf("Enter an integer monetary value: \n");
scanf("%d", &value);
 
count += value / 50;
value %= 50;
 
count += value / 25;
value %= 25;
 
count += value / 10;
value %= 10;
 
count += value / 5;
value %= 5;
 
count += value / 1;
value %= 1;
 
printf("Minimum number of coins required is: %d\n", count);
 
return 0;
}

--- End code ---
?

TheQuirk:
Yup! Good job.

Now, would anyone be interested in me breaking up the last challenge into multiple parts with hints?

worker201:

--- Quote from: sledz41 ---Therefore the code would be:

--- Code: ---program

--- End code ---
?
--- End quote ---

Well, that works, I guess.  But I don't think it is good style.  To switch to a different currency system, such as Britain, who uses 2pence coins, would be very difficult.  Adding bills to the concept is also problematic, since you would have to at least double the amount of code.  My version, using a single array to contain all the possible values, is much more easily converted - no matter what kind of monetary system you want to implement, you only have to change one line.

Although I realize that this was an exercise in thinking, maintainability and portability are almost as important as algorithm design, these days.  Good computer programming is a marriage of design and implementation.

worker201:

--- Quote from: TheQuirk ---Yup! Good job.

Now, would anyone be interested in me breaking up the last challenge into multiple parts with hints?
--- End quote ---
You mean this one?
http://www.microsuck.com/forums/showthread.php?t=10050

Sure, go ahead.

Navigation

[0] Message Index

[*] Previous page

Go to full version