C++ - Butcher Shop

Produce receipts for ABC Butcher Shop

Main

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

//Assignment #2 - Steven Bartsch - COMP 1100
//Produce receipts for ABC Butcher Shop

int main(){
    //Housekeeping
    int quantity;
    double price,extPrice,totalPrice;
    string customer, meat;
    char choice;
    const double BEEF_COST = 7.95, PORK_COST = 6.80, CHICKEN_COST = 5.49;

    ofstream fout("receipt.txt");
    if (!fout.is_open()){
        cout << "Error: Cannot Open File";
        system("pause");
        exit(-1);
    }

    fout << fixed << setprecision(2);
    cout << fixed << setprecision(2);

    //Input
    cout << "Enter Customer Name or ^Z to End > ";
    getline(cin, customer);

    while (!cin.eof()){
        fout << "       ABC Butcher Shop Receipt       " << endl << endl;
        fout << "Customer: " << customer << endl << endl;
        fout << "Meat Purchased" << endl << endl;
        totalPrice=0.0;
        cout << "Enter (B)eef, (P)ork, (C)hicken or (X) to End? ";
        cin >> choice;
        choice = toupper(choice);
            while (choice != 'X'){
                while (cin.fail() || choice !='B' && choice !='P'  && choice != 'C'){
                    cin.clear();
                    cin.ignore(80,'\n');
                    cout << "Enter (B)eef, (P)ork, (C)hicken or (X) to End? ";
                    cin >> choice;
                    choice=toupper(choice);
                }
                    cin.ignore(80,'\n');

                cout << "Enter weight of meat (in kgs) > ";
                cin >> quantity;
                    while (cin.fail() || quantity <0 || quantity > 24){
                    cin.clear();
                    cin.ignore(80,'\n');  
                    cout << "Weight must be between 0-24." << endl;
                    cout << "Enter weight of meat (in kgs) > ";
                    cin >> quantity;
                }
                    cin.ignore(80,'\n');
                //Processing
                if(choice == 'B'){
                    price=BEEF_COST;
                    meat="BEEF";
                }
                else if (choice=='P'){
                    meat="PORK";
                    price=PORK_COST;
                }
                else{
                    price=CHICKEN_COST;
                    meat="CHICKEN";
                }
                    if (quantity > 0){  
                    extPrice=price*quantity;
                    totalPrice+=extPrice;
                    //Output
                    fout << left << setw(18) << meat << setw(2) << quantity << "@ " << setw(3) << price << "/kg" << right << setw(8) << extPrice << endl;
                }
                cout<< "Enter (B)eef, (P)ork, (C)hicken or (X) to End? ";
                cin >> choice;
                choice=toupper(choice);
            }

        if (totalPrice>0){
            fout << endl << left << setw(29) << "Total" << right << setw(8) << totalPrice << endl;
            fout << left << "THANK YOU!" << endl << endl;
        }
        else{
            fout << "Transaction Aborted" << endl << endl;
        }
            fout << "________________________________________" << endl << endl;
            cout << "Enter Next Customer Name or ^Z to End > ";
        cin.ignore(80,'\n');
        getline(cin,customer);
    }
    cout << "Cash Closed"<< endl;
    system("type receipt.txt");
    system("pause");
}

Receipt

       ABC Butcher Shop Receipt       

Customer: John Doe

Meat Purchased

CHICKEN           12@ 5.49/kg   65.88
PORK              21@ 6.80/kg  142.80
BEEF              9 @ 7.95/kg   71.55
BEEF              19@ 7.95/kg  151.05

Total                          431.28
THANK YOU!

________________________________________

       ABC Butcher Shop Receipt       

Customer: Jane Smith

Meat Purchased

CHICKEN           2 @ 5.49/kg   10.98
BEEF              12@ 7.95/kg   95.40
PORK              12@ 6.80/kg   81.60

Total                          187.98
THANK YOU!

________________________________________