Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,562 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,889 people online right now. Registration is fast and FREE... Join Now!




Money Dispenser

 
Reply to this topicStart new topic

Money Dispenser

trixieIam
5 May, 2008 - 09:41 AM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2008
Posts: 10

The program is suppose to ask the user to enter an amount that's a multiple of 10, and then display the amount using the least number of bills, which are 10s, 20s, and 50s. I don't what to use to get the least number of bills. Should I use a loop, if statement?

CODE

#include <iostream>

using namespace std;

int dispense(int amount, int *ten, int *twenty, int *fifty);
int main()
{
    int amt;
    int tens;
    int twenties;
    int fifties;

    cout << "Enter the amount desired (must be a multiple of 10 dollars) : ";
    cin >> amt;

    dispense(amt, &tens, &twenties, &fifties);

    cout << "Number of fifties : " << fifties << "\n";
    cout << "Number of twenties : " << twenties << "\n";
    cout << "Number of Tens : " << tens << "\n";
    return 0;
}
int dispense(int amount, int *ten, int *twenty, int *fifty)
{

    *fifty = amount/50;
    *twenty = amount/ 20;
    *ten = amount/10;

}

User is offlineProfile CardPM
+Quote Post

jeronimo0d0a
RE: Money Dispenser
5 May, 2008 - 01:29 PM
Post #2

D.I.C Head
**

Joined: 3 Mar, 2008
Posts: 141


My Contributions
use:
while( amt >= 50 ) { 50's++ ; amt -= 50 ; }
while( amt >= 20 ) { 20's++ ; amt -= 20 ; }
while( amt >= 10 ) { 10's++ ; amt -= 10 ; }
Etc.
Hope this helps,
Jeronimo
User is offlineProfile CardPM
+Quote Post

Ambercroft
RE: Money Dispenser
6 May, 2008 - 06:16 PM
Post #3

D.I.C Head
Group Icon

Joined: 5 Jan, 2007
Posts: 107



Thanked: 3 times
Dream Kudos: 25
My Contributions
Once you have the number of 50s, calculate the amount left then calculate your 20s required.
Same again for each bill required.

new_amount = amount - ( 50 * number of fifties )

jeronimo0d0a's method is better if the known amounts are small.

User is offlineProfile CardPM
+Quote Post

Whizzy
RE: Money Dispenser
6 May, 2008 - 07:20 PM
Post #4

Unregistered





Kind of like this:


cpp
#include <iostream>

using namespace std;

int process(int cash)
{
int num,tens,twenties,fifties=0;
while (cash>=50){
fifties++;
cash=cash-50;
}
cout << "You used "<<fifties<<" $50.00 bills"<<endl;
twenties=0;
while (cash>=20){
twenties++;
cash=cash-20;
}
cout << "You used "<<twenties<<" $20.00 bills"<<endl;
tens=0;
while (cash>=10){
tens++;
cash=cash-10;
}
num=fifties+twenties+tens;
cout << "You used "<<tens<<" $10.00 bills"<<endl;
return (num);
}


int main(){
int amt;
int d;
cout << "Enter the amount desired (must be a multiple of 10 dollars) : ";
cin >> amt;
cout <<"You have entered $"<<amt<<".00"<<endl;
d=process(amt);
cout << "You need a minimum of "<< d <<" bills."<<endl;
system ("PAUSE");
}



+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:44PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month