Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 21st, 2004, 4:37 AM   #1
sara
Newbie
 
Join Date: Sep 2004
Posts: 1
Rep Power: 0 sara is on a distinguished road
Can someone help me do this program???

The program reads a whole change amount in dollars and prints how many 500 dollars bills,200 dollars bills,100 dollars bills ,50 dollars bills ,20 dollars bills ,10 dollars bills 5 dollars bills ,and 1 dollars coins should the cashier return to the customer.
for example,if the cashier enters 2789 dollars,the program should print:
amount entered:2789 dollars
5-500 dollars bills
1-200 dollars bills
1-50 dollars bills
1-20 dollars bills
1-10 dollars bills
1-5 dollars bills
4-1 dollars coins

the program should read many positive values and calculate the change for each one. the program should stop when you enter a 0 or a negative value
I want to use function, array and loop.


I will appreciate your help.
sara is offline   Reply With Quote
Old Sep 21st, 2004, 6:01 AM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Post what you have tried so far.

Basically what you need to do is divide by 500, take the remainder of that with the modulus operator, divide by 200, take the remainder of that, divide by 50, and so on. As for stopping at 0, or a negative number, you could use something like this:

int x;
scanf("%d", &x);

for(x;x>0;)
{
     printf("You need %d 500-dollar bills", x/500);
     x = x % 500;
     printf("You need %d 200-dollar bills", x/200);
     x = x % 500

     /* code the rest of it*/

     scanf("%d", &x);
}
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Sep 21st, 2004, 6:41 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
I did not know you could get a negative number with modulus.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Sep 21st, 2004, 7:54 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Sara, show us what you have done so far... and where you are having errors. I would hate to do the assign for you, as you will not learn anything and it will do more harm than good. Mjordan2nd is right in regards to the use of the modulus operator.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Sep 21st, 2004, 10:29 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
oh and to my earlier post i wrote a quick ditty in C++ and got a negative number.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Sep 21st, 2004, 10:45 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
btw - Welcome to the forums!
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC