![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 1
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
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 |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|