A seller needs you to generate a program such that whenever a customer purchases some items and pays for the bill. The seller accepts at max $10 denominations. Your program takes input of payment amount and purchase amount. So u need to give an output of the return change to the customer. The return change should be in
$10, $5, $1, $0.25, $0.10, $0.05, $0.01
It should give the best possible combination.

pls help coding this..

thanks

Well, lets see what you have so far.

void printChange(float amountToReturn)
{
int atr = amountToReturn;
cout<<"Nos of $1 Bills : "<<atr;
amountToReturn -= ((float) atr);
atr = (amountToReturn * 100.0);
cout<<"25 Cents : "<<(atr / 25);
atr %= 25;
cout<<"10 Cents : "<<(atr / 10);
atr %= 10;
cout<<"5 Cents : "<<(atr / 5);
atr %= 5;
cout<<"1 Cents : "<<atr;
}

Not a bad start to the function. You might want to expand that for change up to 10 dollars rather than single dollar bills being the highest denomination of change available, but otherwise the concept is good.

Now for a question rather than a request.

I've always wondered, is this:

int atr = amountToReturn;

a good/safe way of truncating the decimal portion of a float/double? Should it be type-cast? Or should you use the floor() function?

I've always wondered, is this:

int atr = amountToReturn;

a good/safe way of truncating the decimal portion of a float/double? Should it be type-cast? Or should you use the floor() function?

All the didgets after the decimal point are ignored when converting to an integer, there is no need for type casting.

Hi First i am doing it for int cos to avoid casting and later on i ll do it float ,....but the error giving here is:

xyz.cpp:37: error: a function-definition is not allowed here before '{' token
xyz.cpp:53: error: a function-definition is not allowed here before '{' token

#include<iostream>
#include<stdlib>
using namespace std;

void printRem( float r);
void printLten(float r);


int main()
{
        int saleAmt;
        int paidAmt;
cout << " enter the amount customer has given" << endl;
cin >>paidAmt;
cout <<" enter the sale price or amt " <<endl;
cin >>saleAmt;
if(paidAmt > saleAmt)
{
        int rem;
        rem = (saleAmt%paidAmt);
        do
        {
                printRem(rem);

        }while (rem > 10);

     /*   do
        {
                printLten(rem);

        } while (rem >5);
*/


void  printRem(int &r) //lessthan ten
 {
        int  money;
        money = (r%10);
        if(money <10)
        {
                 do
               {
                   printLfive(rem);

                } while (rem >5);
         }


}

void printLfive(int &reminder) //less than 5
 {
        int money1;
        money1 = (r/5);
        if(money1 <5)
}
commented: For not using code tags +0

There is no '}' ending main(). Btw, if you put your code in code tags and specify a language, like [ CODE=C++ ] (w/o spaces), the lines will be numbered, making it easier to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.