Hi all, just a quick question for C programmers. I have to write a program that prompts a user to enter how much money they wish to withdraw in multiples of 10's. Then it returns the requested amount in 10's, 20's or 50's. But I have to write it by using output parameters or pointers. Obviously I'm gonna have to use a loop here. What kind of loop do you recommend and how many? I wouldn't use a "for" loop because those are only for when you have a pre-defined number correct? Thanks.
What kind of loop do u recommend I use for this ATM program in C?
Not quite sure why you need to use a loop here, unless you are talking about looping until the user is done entering data like
while(moreUserInput())
{
do_something_with_user_input();
}
To figure out what denominations to give out you can use the mod operation which will give you the remainer of what you divide by so
num50s = amt / 50;
amt = amt % 50;
num20s = amt / 20;
amt = amt % 20;
num10s = amt / 10;
amt = amt % 10; // This should be zero if your entry program is working correctly
Reply:Just use the modulus operator -- no loops
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment