...

Modular Programming - What's wrong w/my code?

Jus S
11-21-2008, 03:15 AM
I need to write a program for an automatic teller machine that dispenses money. The user should enter the desired amount (multiples of 10 dollars) and teh machine dispenses that amount using the least number of bills. The bills dispensed are 50s, 20s, and 10s. I also need to specify how many of each kind of bill to dispense. My mess of a code is attached. Help

#include <stdio.h>
#include <math.h>

int GetBills(int dollars, int* fifties, int* twenties, int* tens)

{
*fifties = dollars / 50;
*twenties = (dollars %= 50) / 20;
*tens = (dollars %= 20) / 10;

return *fifties || *twenties || *tens;
}

void PrintBills(int dollars, int fifties, int twenties, int tens)
{
printf("\nDispensing %d dollars ...", dollars)
if (fifties)
printf("\n%d \$50 bills", fifties);
if (twenties)
printf("\n%d \$20 bills", twenties);
if (tens)
printf("\n%d \$10 bills", tens);
}

mic2100
11-21-2008, 02:12 PM
i am not sure how you would program this in C or C++ but i think the logic needs to be set out like so...

I have checked the logic using PHP and it works fine so u will just need to convert into wot eva u need it to be

void get_bills(int amount)
{

check50 = amount / 50;

if(check50 > 1) //more than 50 requested
{

total50s = round_down(check50);
remaining = amount - (total50s * 50);

}
else
{

total50s = 0;
remaining = amount;

}

check20 = remaining / 20;

if(check20 > 1) //more than 20 remaining
{

total20s = round_down(check20);
remaining = remaining - (total20s * 20);

}
else
{

total20s = 0;
remaining = remaining;

}

check10 = remaining / 10;

if(check10 >= 1) //more than 10 remaining
{

total10s = round_down(check10);

}
else
{

total10s = 0;

}

output['50s'] = total50s;
output['20s'] = total20s;
output['10s'] = total10s;

return output
}

Hope this helps

Millenia
11-21-2008, 06:30 PM