Cashier 1.0 is a C++ program that displays on the screen item codes with corresponding item description and price (at least 10 items). It asks the user to enter the code of the item purchased by a customer. Then, its description and price are displayed on the screen too. Also, it asks for the quantity of the particular item code entered. Consequently, it displays the total amount due. Then, it asks the user to tender the amount of cash of the customer. Finally, it displays the change and its breakdown.

Constraints:

When any one of the scenarios happens, the program should exit.
• The user enters item codes that are not available.
• The user types in quantity less than or equal to 0.
• The user inputs amount of cash less than the amount due.

Grading Criteria:

Program Correctness 80%
Ease of Use 20%

Sample Run:
Welcome to CS131xxx Mart!
Item Codes Description Price
100 Sweet ‘n Ripe Grapes 302.90
101 Crunchy Apples 52.20
… … …
109 Green Peas 25.75

Enter Code: 100
Sweet ‘n Ripe Grapes 302.90 Qty: 1


Total Due: 302.90
Cash: 1000.00
Change: 697.10


=========== CHANGE BREAKDOWN ===========
1000 0 0
500 1 500.00
200 0 0
100 1 100.00
50 1 50.00
20 2 40.00
10 0 0
5 1 5.00
1 2 2.00
0.25 0 0
0.10 1 0.10
0.05 0 0

“ Thanks for shopping!”

its in c++ . . . the breakdown is the hardest part so i was tryin to make a program of it for my hw . . . but its kinda hard . . . ok for example . . . the change that the cashier is gon to give to the customer is lets say $1250 . . . in the breakdown it will say how many 1000 , 500, 200, 100, 50, 20, 10, 5, 1, 0.25, 0.10, 0.05 are there in the change . . .

so far this is wot i have finished and im not sure if my codes are correct . . .

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

void main()
{

int code, qty, cash;
double tDue, change;


cout<<"Welcome to CS131xxx Mart!"<<endl<<endl;
cout<<"Item Codes Description Price"<<endl<<endl;
cout<<"100 Sweet 'n Ripe Grapes 302.90"<<endl;
cout<<"101 Crunchy Apples 52.20"<<endl;
cout<<"102 Green Peas 25.75"<<endl;
cout<<"103 Oranges 60.75"<<endl;
cout<<"104 Melons 135.40"<<endl;
cout<<"105 Ripe Mangos 90.50"<<endl<<endl;

cout<<"Enter Code: ";
cin>>code;


switch (code)
{
case 100: cout<<"Sweet 'n Ripe Grapes 302.90";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=302.90*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}


break;

case 101: cout<<"Crunchy Apples 52.20";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=52.20*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}

break;

case 102: cout<<"Green Peas 25.75";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=25.75*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}

break;

case 103: cout<<"Oranges 60.75";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=60.75*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}

break;

case 104: cout<<"Melons 135.40";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=135.40*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}

break;

case 105: cout<<"Ripe Mangos 90.50";
cout<<" Qty: ";
cin>>qty;

{
if (qty<0)
cout<<"Invalid Quantity Number"<<endl;
else
tDue=90.50*qty;
cout<<"Total Due: "<<tDue<<endl;
}

cout<<"Cash: ";
cin>>cash;

change=cash-tDue;

{
if (cash<0 || cash<tDue)
cout<<"Invalid Cash"<<endl;
else
cout<<"Change: "<<change<<endl<<endl;
}

break;

default: cout<<"Invalid Item Code"<<endl<<endl;

}

cout<<"=============== CHANGE BREAKDOWN ==============="<<endl;

Hey,

First off, please use code tags when displaying code as it will make it much easier for everybody to read.

I have looked through the code you have so far and it looks pretty good, but I have made a few changes for the sake of functionality and the sake of readability:

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

void main(void)
{

     int code, qty, cash;
     double tDue, change;


     cout<<"Welcome to CS131xxx Mart!\n"<<endl;
     cout<<"Item Codes Description Price\n"<<endl;
     cout<<"100 Sweet 'n Ripe Grapes 302.90\n"
         <<"101 Crunchy Apples 52.20\n"
         <<"102 Green Peas 25.75\n"
         <<"103 Oranges 60.75\n"
         <<"104 Melons 135.40\n"
         <<"105 Ripe Mangos 90.50\n"
         <<endl;

     cout<<"Enter Code: ";
     cin>>code;


     switch (code)
     {
          case 100: cout<<"Sweet 'n Ripe Grapes 302.90";
             cout<<" Qty: ";
             cin>>qty;

             while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }

             tDue=302.90*qty;
             cout<<"Total Due: "<<tDue<<endl;
 
             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;

             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;

             break;

          case 101: cout<<"Crunchy Apples 52.20";
             cout<<" Qty: ";
             cin>>qty;

             while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }
             tDue=52.20*qty;
             cout<<"Total Due: "<<tDue<<endl;

             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;


             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;

             break;

          case 102: cout<<"Green Peas 25.75";
             cout<<" Qty: ";
             cin>>qty;

             while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }
             tDue=25.75*qty;
             cout<<"Total Due: "<<tDue<<endl;

             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;

             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;

             break;

          case 103: cout<<"Oranges 60.75";
             cout<<" Qty: ";
             cin>>qty;

             while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }
             tDue=52.20*qty;
             cout<<"Total Due: "<<tDue<<endl;

             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;

             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;

             break;

          case 104: cout<<"Melons 135.40";
             cout<<" Qty: ";
             cin>>qty;

             while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }
             tDue=52.20*qty;
             cout<<"Total Due: "<<tDue<<endl;

             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;

             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;

             break;

          case 105: cout<<"Ripe Mangos 90.50";
             cout<<" Qty: ";
             cin>>qty;

            while (qty<0)
             {
                  cout<<"Invalid Quantity Number"<<endl;
                  Cin >> qty;
             }
             tDue=52.20*qty;
             cout<<"Total Due: "<<tDue<<endl;

             cout<<"Cash: ";
             cin>>cash;

             change=cash-tDue;

             while (cash<0 || cash<tDue)
             {
                  cout<<"Invalid Cash"<<endl;
                  cin >> cash
                  change = cash-tDue
              }
              cout<<"Change: "<<change<<endl<<endl;
             break;

          default: cout<<"Invalid Item Code"<<endl<<endl;

     }

cout<<"=============== CHANGE BREAKDOWN ==============="<<endl;

Use a while loop instead of an if/else statement to allow the user to input an incorrect value more than once. I will see if I can help with the code for a change breakdown. What do you have of it so far?

-D

I actually made a mistake above. It should be:

int main(void)
{
}
//not
void main(void)
{
}

Sorry about that! Also make sure that you have your return 0 statement at the end of your main block.

-D

i dun really have any codes for the change breakdown yet cuz i duno how to do it using switch statement

so far this wot i have finished for the breakdown...can sumone pls help with the codes

if (a>0)
cout<<"1000 0 "<<a<<endl;
else
cout<<"1000 0 0"<<endl;

b=change-1000;
c=int(b/500);

if (c>0)
cout<<"500 0 "<<c<<endl;
else
cout<<"500 0 0"<<endl;

d=change-1500;
e=int(d/200);

if (e>0)
cout<<"200 0 "<<e<<endl;
else
cout<<"200 0 0"<<endl;

f=change-1700;
g=int(f/100);

if (g>0)
cout<<"100 0 "<<g<<endl;
else
cout<<"100 0 0"<<endl;

h=change-1800;
i=int(h/50);

if (i>0)
cout<<"50 0 "<<i<<endl;
else
cout<<"50 0 0"<<endl;

j=change-1850;
k=int(j/20);

if (k>0)
cout<<"20 0 "<<k<<endl;
else
cout<<"20 0 0"<<endl;

m=change-1870;
n=int(m/10);

if (n>0)
cout<<"10 0 "<<n<<endl;
else
cout<<"10 0 0"<<endl;

o=change-1880;
p=int(o/5);

if (p>0)
cout<<"5 0 "<<p<<endl;
else
cout<<"5 0 0"<<endl;

q=change-1885;
r=int(q/1);

if (r>0)
cout<<"1 0 "<<r<<endl;
else
cout<<"1 0 0"<<endl;

This article has been dead for over six months. Start a new discussion instead.