Hi im creating a cash register program. The user enter's the total price and the money given from customer and the customer's change is shown. It will tell the user what notes/coins to give to the customer.
I could do this

But the next part i have to do is check how many coins and notes are left, and if get's below 10, the user must be notified. I'm going to put hundred of each. This part i can't do. I have used separate functions for both these parts of the program.

Here is the code I've done so far.

#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

void transaction();
void tillStore();
void exit();

float totalToPay, cashGiven;
char userResponse; 
int userChoice;



////////////////////////////////start main//////////////////////////////////////  
int main()

{   
    cout<<"\n\n\t\t\t    Macy's Department Store"; 
    cout<<"\n\n\n\n\n\t\t\t Select an Option from the Menu";  
    cout<<"\n\n\n\t\t\t\t1.Transaction";   
    cout<<"\n\n\t\t\t\t2.Till Store"; 
    cout<<"\n\n\t\t\t\t3.Exit\n";

    cout<<endl;    
    cout<<"\t\t\t\tOption: "; 
    cin>>userChoice;
    cout<<endl;

    switch(userChoice)

    {
      case 1:transaction();break;
      case 2:tillStore();break;   
      case 3:exit();break;                  

      default: cout<<"Please Select a Correct Option";

    }

}//end main

///////////////////////void transaction/////////////////////////////////////////    
void transaction()
{

system ("CLS");
cout<<"\n\n\t\t\t\tTransaction";    
cout << "\n\n\nENTER YOUR TOTAL: ";
cin>> totalToPay;
cout<< endl;


cout << "Total COST Is: " ;
cout << setprecision (4) << totalToPay <<  endl;
cout << fixed;
cout<< endl;

cout<<endl;
cout<< "CASHIER, Please Enter Total CASH PAID: " ;
cin >> cashGiven;

if(cashGiven > totalToPay) {

    cout<<endl;
    cout<< "YOU HAVE ENTERED: " << setprecision (5) << cashGiven << endl;
    cout<<fixed;
    cout<<endl;

    cout << "\nCUSTOMER's CHANGE IS: " << setprecision (2)<< cashGiven - totalToPay << endl;

    cout << "\nCASHIER Please Give The Following Change: "<< setprecision (2) << endl;

    float changeRemaining = cashGiven - totalToPay;

    int fifty = int(changeRemaining) / 50;

    if(fifty >= 1) {
            cout <<"\n50: "<< fifty <<endl;
            changeRemaining -= 50*fifty;
            }
    else {
         cout <<"\n50:" << endl;
         }

    int twenty = int(changeRemaining) / 20;

    if(twenty >= 1) {
            cout <<"20: "<< twenty <<endl;
            changeRemaining -= 20*twenty;
            }
    else {
         cout <<"20:" << endl;
         }

    int ten = int(changeRemaining) / 10;

    if(ten >= 1) {
            cout <<"10: "<< ten <<endl;
            changeRemaining -= 10*ten;
            }
    else {
         cout <<"10:" << endl;
         }

    int five = int(changeRemaining) / 5;

    if(five >= 1) {
            cout <<"5: "<< five <<endl;
            changeRemaining -= 5*five;
            }
    else {
         cout <<"5:" << endl;
         }

    int twopound = int(changeRemaining) / 2;

    if(twopound >= 1) {
            cout <<"2: "<< twopound <<endl;
            changeRemaining -= 2*twopound;
            }
    else {
         cout <<"2:" << endl;
         }

    int onePound = int(changeRemaining) / 1;

    if(onePound >= 1) {
            cout <<"1: "<< onePound <<endl;
            changeRemaining -= 1*onePound;
            }
    else {
         cout <<"1:" << endl;
         }

    double fiftyPence = changeRemaining / 0.5;

    if(fiftyPence >= 1) {
            cout <<"50p: " << fiftyPence <<endl;
            changeRemaining -= 0.5*fiftyPence;
            }
    else {
         cout <<"50p:" << endl;
         }

    double twentyPence = changeRemaining / 0.2;

    if(twentyPence >= 1) {
            cout <<"20p: " << twentyPence << endl;
            changeRemaining -= 0.2*twentyPence;
            }
    else {
         cout <<"20p:" << endl;
         }

    double tenPence = changeRemaining / 0.1;

    if(tenPence >= 1) {
            cout <<"10p: " << tenPence << endl;
            changeRemaining -= 0.1*tenPence;
            }
    else {
         cout <<"10p:" << endl;
         }

    double fivePence = changeRemaining / 0.05;

    if(fivePence >= 1) {
            cout <<"5p: " << fivePence << endl;
            changeRemaining -= 0.05*fivePence;
            }
    else {
         cout <<"5p:" << endl;
         }

    double twoPence = changeRemaining / 0.02;

    if(twoPence >= 1) {
            cout <<"2p: " << twoPence << endl;
            changeRemaining -= 0.02*twoPence;
            }
    else {
         cout <<"2p:" << endl;
         }


    double onePence = changeRemaining / 0.01;

    if(onePence >= 1) {
            cout <<"1p: " << onePence + 1 << endl;
            changeRemaining -= 0.01*onePence;
            }
    else {
         cout <<"1p:" << endl;
         }
}
else {
     cout << "Customer has not paid enough";
     }

     //if user wants to return to main menu.
     cout<<"\n\n\nWould You like to return to the main Menu?: Y/N\n";
     cin>>userResponse;

     if (userResponse=='y')//start if statement.

     {
        system("CLS");        
        main();
     }//end if statement.

     else 

     system ("CLS");

     system ("PAUSE");

}//end void transaction()

/////////////////////////void tillStore/////////////////////////////////////////
void tillStore()
{

 system ("CLS");
 cout<<"\n\n\t\t\t\tTill Store";    
 cout<<"\n\n\nWould You like to return to the main Menu?: Y/N\n";
     cin>>userResponse;

     if (userResponse=='y')//start if statement.

     {
        system("CLS");        
        main();
     }//end if statement.

     else 

     system ("CLS");     
     system ("PAUSE");
}//end void stillStore

//////////////////////////////void exit/////////////////////////////////////////
void exit()

{     
      cout<<"Goodbye\n";
      system ("CLS");        
}//end exit().

ANY HELP WOULD BE WONDERFUL.

Thank You.

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

You failed to use code tags...

How do I do that?

commented: I dunno, maybe read the half-dozen "READ THIS FIRST" type posts all over the place which tell you how to. This lazyness is pathetic -4

How do I do that?

Let me count the ways:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in!

Does this help?

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.