Hi guys I am really having trouble on what to do with my program. We are asked to make a cashier's program and I don't know how to do the the Receipt... I don't know what to do in the order part... how about if the customer will order 3 of my products?? I also don't know how to do the calculation part ... can you help me ??

#include<iostream>
using namespace std;


void partsList(){
    float mouse, keyboard, monitor, CPU, Package;
    mouse=100;
    keyboard=120;
    monitor=300;
    CPU=500;
    Package=3000;

    //THE PRODUCTS
    cout<<endl;
    cout<<"Mouse      -   P "<<mouse<<endl;
    cout<<"Keyboard   -   P "<<keyboard<<endl;
    cout<<"Monitor        -   P "<<monitor<<endl;
    cout<<"CPU        -   P "<<CPU<<endl;
    cout<<"Package        -   P "<<Package<<endl;
};



int main(){

    string Fname, Lname, age, add, cnum;

    //CASHIERS INFORMATION
    cout<<"First Name: ";
    cin>>Fname;
    cout<<"Last Name: ";
    cin>>Lname;
    cout<<"Input Age: ";
    cin>>age;
    cout<<"Address: ";
    cin>>add;
    cout<<"Contact #: ";
    cin>>cnum;

    partsList();

    string orders;
    char any;
    char y;
cout<<endl;

//THE RECEIPT
cout<<"     Nicole's Computer Shop!!    "<<endl;    
cout<<"*********************************"<<endl;
//THE ORDER OF THE CUSTOMER  
    cout<<"Orders: ";
    cin>>orders;

cout<<"Your order is: "<<orders;

cout<<endl<<endl<<endl;
cout<<"*********************************"<<endl;
cout<<"Cashier: "<<Fname<<" "<<Lname<<endl;


}

What exactly are the program requirements?

I don't know how to do the the Receipt

Does the question specify how the receipt should look like? If not it is up to you, take any slip you have and try to implement it using the common output stream "cout".

how about if the customer will order 3 of my products??

one very basic option would be if you display a menu to the user with all the available products and you allow the user to make only one choice, then ask the user to input the number of that product he/she wants to buy.
e.g:
1 for Pen
2 for Pencil
3 for NoteBook
please enter your choice(1,2 or 3)

I also don't know how to do the calculation part

Just go to Google or read any basic maths book, sure you will find something on how to perform basic financial calculation, like finding the total cost for a certain number of products, etc.

Do you know what a struct (a data record) is ?

Do you know how to use arrays?

One nice way to handle this might be to create a const array of pairs of (product, price) ...

Maybe something like this:

#include <string>

// ...

struct Item
{
    string name;
    float price;
} ;

const Item ITEMS[] =
{
    {"mouse", 100},
    {"keyboard", 129},
    {"monitor", 300},
    {"CPU",500}
    {"Package", 3000}
} ;

const int NUM_ITEMS = sizeof ITEMS/ sizeof *ITEMS;

Then could use a struct Order,
maybe something like this:

struct Order
{
    int id;
    int quanity[NUM_ITEMS];
    float getTotal() const;
    {
        float sum = 0;
        for( int i = 0; i < NUM_ITEMS; ++ i )
        {
            sum += quanity[i]*ITEMS[i].price;
        }
        return sum;
    }
} ;

Then, maybe a takeInOrder function
something like this:

void takeInOrder( Order& ord )
{
    ord.id = takeInInt( "Enter the order id" );
    for( int i = 0; i < NUM_ITEMS; ++ i )
    {
        ord.quanity[i] = takeInInt( "How many " + ITEMS[i].name + ": " );
    }
}

Of course the above, pre-supposes that you have already defined a function like ...

int takeInInt( const string& msg )
{
    while( true )
    {
        cout << msg << flush;
        int tmp;
        if( cin >> tmp && cin.get() == '\n' && tmp >= 0 )
            return tmp;
        // else ...
        cin.clear(); // clear any error flags
        cin.sync(); // 'flush' cin stream
        cout << "\nPlease enter only integers >= 0 here ...\n";
    }
}


// ...

Then in main .... something like this:

int main()
{
    do
    {
        Order ord;
        takeInOrder( ord );
        float total = ord.getTotal();
        // show and whatever else you need
        // ...
    }
    while( more() ); 
    // of couse you will need to define a 'more'
    // function that asks re. 'more' (y/n) ?
}

A 'more' function could look something like this:

bool more()
{
    cout << "More (y/n) ? " << flush;
    string reply;
    getline( cin, line );
    if( line.size() > 0 && line[0] != 'n' )
        return false;
    // else ...
    return true;
}

Edited 1 Year Ago by David W

Oops ... (some) typos above fixed now,
please see this 'fix' below:

bool more() // defaults to yes, more //
{
    cout << "More (y/n) ? " << flush;
    string reply;
    getline(cin, reply);
    if(reply.size() > 0 && tolower(reply[0]) == 'n')
        return false;
    // else ...
    return true;
}

There are other typos ...

For an example of a critical one,
a comma is missing in the array above,

a 'non-lethal' typo,
'quantity' is mispelled above.

a 'lethal' ...
float getTotal() const; // what is wrong with ; here?

Edited 1 Year Ago by David W

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