![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 3
Rep Power: 0
![]() |
Hello every one,
I am stuck with the following problem, it's the course final assignment of my 'structured programming' course at the univerisity. I'm student of EEE, and therefor I'm not much into programming... I know it's cheating, but I would really be thankful if some can kindly solve the problem for me, I really don't want to get a double zero :o Here's the problem, and it should be solved with C (no C++): Write a program to dispense change.The user enters the amount paid and the amount due. The program determines how many dollars, 50cents, 20cents, 10cents should be given as change. a) write a function with the heading: void dispense(int change,int *dollars,int *c10,int *c20,int *c50) that determines and return the quantity of each kind of coin. (Note:16 cents-5 cents=11 cents meaning that one 10cents is returned for charge.However 16 cents-1 cents=15 cents meaning that one 20-cents is required(round-up)) b) write a function int getData(int *paid,int *due) that doe the following: inform the user that amount paid and amount due should be entered in cents(integer) do prompt the user to enter the amount paid and amount due read in the data while (amount due<0 or amount paid<amount due); if both amount paid and amount due are zeros return 0 otherwise return 1 following until both the amount paid and amount due are zeros. 1.call the function getData to ask for the amount paid and amount due 2.print out the charge and the # of each kind of coins to dispense. Program output: The amount-paid and amount-due should be entered in cents (integer) To terminate the program,enter 0 for both values Enter the amount paid and amount due please:16 5 amount due:5,amount paid:16,and thus change=11 You are suggested to give him/her 1 10-cents coin(s) The amount-paid and amount-due should be entered in cents (integer) To terminate the program,enter 0 for both values Enter the amount paid and amount due please:26 5 amount due:5,amount paid:26,and thus change=21 You are suggested to give him/her 1 20-cents coin(s) The amount-paid and amount-due should be entered in cents (integer) To terminate the program,enter 0 for both values Enter the amount paid and amount due please:66 5 amount due:5,amount paid:66,and thus change=61 You are suggested to give him/her 1 50-cents coin(s) 1 10-cents coin(s) The amount-paid and amount-due should be entered in cents (integer) To terminate the program,enter 0 for both values Enter the amount paid and amount due please:81 5 amount due:5,amount paid:81,and thus change=76 You are suggested to give him/her 1 50-cents coin(s) 1 20-cents coin(s) 1 10-cents coin(s) The amount-paid and amount-due should be entered in cents (integer) To terminate the program,enter 0 for both values Enter the amount paid and amount due please:5 81 Enter the amount paid and amount due please:0 0 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Shit, i actually had this program already done... let me fumble around with some floppies and see if i can find it.
__________________
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2005
Posts: 3
Rep Power: 0
![]() |
Oops, I posted on the wrong forum! Sorry guys! Actually I'm too tensed about the grade... I've got to study for three other subjects! I hate school!
tempest, it would be great if you can help... my address is rimina1985@yahoo.com. Thanks in advanced. |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Post it here too - I'm curious.
|
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
~moved
__________________
"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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2005
Posts: 3
Rep Power: 0
![]() |
Here's what I wrote. Not to mention, this doesn't work :(
#include <stdio.h> int getData(int *paid,int *due){ printf ("\nThe amount-paid and amount-due should be entered in cents(integer)"); do { printf ("\nTo terminate the program,enter 0 for both values"); printf ("\nEnter the amount-paid and amount-due please:"); scanf ("%d %d",&paid,&due); } while (due<0||paid<due); if (paid==0&&due==0) return 0; else return 1;} void dispense(int change,int *dollars,int *c10,int *c20,int *c50){ dollars=round(paid-due); change=dollars/10; while (change>=1&&change<=9){ switch (change) { case '1' :c10+=1; break; case '2' :c20+=1; break; case '3' :c10+=1; c20+=1; break; case '4' :c20+=2; break; case '5' :c50+=1; break; case '6' :c10+=1; c50+=1; break; case '7' :c20+=1; c50+=1; break; case '8' :c10+=1; c20+=1; c50+=1; break; case '9' :c20+=2; c50+=1; break; default:printf ("\nCheck your input!"); printf ("\nEnter the amount-paid and amount-due please:"); } } int main () { do { getData();} while getData==1; dispense(); printf ("\namount due:%d",due); printf ("amount paid:%d",paid); printf ("and thus change=%d",change); if (change<5) { if (c20==0){ printf ("You are suggested to give him/her %d 10-cents coin(s)",c10);} if (c10==0){ printf ("You are suggested to give him/her %d 20-cents coin(s)",c20);} else printf ("You are suggested to give him/her %d 10-cents coin(s) %d 20-cents coiu(s)",c10,c20);} else if (change>5) { if (c10==0){ printf ("You are suggested to give him/her %d 20-cents coin(s) %d 50-cents coin(s)",c20,c50);} if (c20==0){ printf ("You are suggested to give him/her %d 10-cents coin(s) %d 50-cents coin(s)",c10,c50);} else printf ("You are suggested to give him/her %d 10-cents coin(s) %d 20-cents coin(s) %d 50-cents coin(s)",c10,c20,c50);} else if (change==5) { printf ("You are suggested to give him/her %d 50-cents coin(s)",c50);} } } Please help me! |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
here is what i got, but the source is in c++ (sorry
)//exact change
#include <iostream>
using namespace std;
void GetExactChange (int total)
{
int quarters, dimes, nickels, pennies, leftOver;
//get amount of quarters
quarters = total/25;
leftOver = total%25;
//get amount of dimes
dimes = leftOver/10;
leftOver = leftOver%10;
//get amount of nickels
nickels = leftOver/5;
leftOver = leftOver%5;;
//get amount of pennies
pennies = leftOver;
cout<<endl<<"From "<<total<<" cents you get: ";
cout<<endl<<quarters<<" quarters";
cout<<endl<<dimes<<" dimes";
cout<<endl<<nickels<<" nickels";
cout<<endl<<pennies<<" pennies"<<endl;
}
int main ()
{
int cents;
char rep[1];
cout<<endl<<"Enter amount of pennies to convert: ";
cin>>cents;
GetExactChange(cents);
cout<<endl<<"Repeat?[Y/N]";
cin>>rep[1];
if(rep[1]=='y') main ();
else return 0;
}sorry that it is not exactly how you wanted your program to be, but i will work on it so that it will be =) |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
lol it only took 540 days to get an answer lol
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
540 days to break the forum's rules regarding homework? Wonderful. You must be very proud. Since it's fucked up, you must be doubly proud. Since it appears many times on every C/C++ forum that ever existed, you must be triply proud. Now, if you'll excuse me, I need to go sniff my ass and puke in my shirt pocket.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|