#include<iostream>
#include<ctime>
#include<iomanip>

using namespace std;


int totcount(int,int,int); //function prototype


void sandtype(int&,int&,int&); //function prototype
void profitandcost(double&, double& ,int ,int ,int ,int ,int ,int ,double, double); //function prototype


//function main begins program execution
int main ()
    {

int sandwichtype, deliverytime;// declare variables
int grandtotalinlbp, grandtotalinusd;
int sandwichcost1, sandwichcost2, sandwichcost3;
int sandwichretailprice1, sandwichretailprice2, sandwichretailprice3;
int counter1 , counter2 , counter3 , counter4 = 0 ; // initialize loop counter
int t1=0 ,sand, repeat;
double profit, cost, deliveryrate, fuelcost;
int array [5][3] ;
        int i = 0;
        int j = 0;

   // Get current date/time, format is MM-DD.HH:mm:ss.YYYY
        time_t now = time(0);
        char* dt = ctime(&now);



   do {


   counter1 = 0;
            counter2 = 0;
            counter3 = 0;
            counter4++;


   do {cout<<"\n"<<"Choose your sandwich type by pressing:"<<"\n" // prompt user
            <<" 1 for cheese sandwich"<<"\n" // output choices
            <<" 2 for veggie sandwich"<<"\n"
            <<" 3 for custom sandwich"<<"\n"
            <<"-1 when you finish your order"<<endl;


   cin>> sandwichtype; ;// read type from keyboard


   if(sandwichtype == 1) // if user chose cheese sandwich
        {counter1++; //increment the counter
        sandwichcost1= 1;
        sandwichretailprice1= 2;}

   else if(sandwichtype == 2) //if user chose veggie sandwich
        {counter2++; //increment the counter
        sandwichcost2= 2;
        sandwichretailprice2=4;}

   else if(sandwichtype== 3) //if user chose custom sandwich
        {counter3++; //increment the counter
        sandwichcost3= 3;
        sandwichretailprice3= 6;}

   else if(sandwichtype !=-1)
        cout<<"\n"<<"Wrong operation please try again."<<endl;

   t1=totcount(counter1,counter2,counter3); //function call

   sandtype(counter1,counter2,counter3); //function call


   } while( sandwichtype!=-1);


   cout<<"\n"<<"Sandwiches total number is "<<t1<<endl;


   do{cout<<"\n"<<"Enter your delivery time by pressing:"<<"\n" // prompt user
            <<" 1 for daytime"<<"\n" // output choices
            <<" 2 for nightime"<<endl;
        cin>> deliverytime; // read values from keyboard

   if(deliverytime!=1 && deliverytime!=2) // if delivery time different than 1 and 2
            cout<<"\n"<<"Wrong operation please try again."<<endl;

   }while(deliverytime!=2 && deliverytime!=1); 



   if(deliverytime == 1) //if delivery was at daytime it will cost 5$ more
        {deliveryrate= 5;}

   else if(deliverytime == 2 ) //if delivery was at nightime it will cost 10$ more
        {deliveryrate= 10;}



   do{cout<<"\n"<<"Enter the fuel cost"<<endl; // prompt user
        cin>> fuelcost; // read values from keyboard

   if(fuelcost<0) // if user enter a negative number
            cout<<"\n"<<"Wrong operation please try again."<<endl;

   }while(fuelcost<0);


   //calculate sandwich retail price
        sandwichretailprice1 = (counter1 * 2);
        sandwichretailprice2 = (counter2 * 4);
        sandwichretailprice3 = (counter3 * 6);

   //calcuate sandwich cost
        sandwichcost1 = (counter1 * 1);
        sandwichcost2 = (counter2 * 2);
        sandwichcost3 = (counter3 * 3);

   //calculate the grand total in LBP
        grandtotalinlbp = (sandwichretailprice1 + sandwichretailprice2 + sandwichretailprice3) * 1500;
        //calculate the grand total in USD
        grandtotalinusd = sandwichretailprice1 + sandwichretailprice2 + sandwichretailprice3;

   // function call
        profitandcost (profit, cost, sandwichretailprice1 ,sandwichretailprice2 ,sandwichretailprice3 ,sandwichcost1 ,sandwichcost2 ,sandwichcost3 ,fuelcost ,deliveryrate); 


   // display the reciepe
       cout<<"\n"<<"Welcome to Sandwich Mania"<<"\n"
           <<dt <<endl; //display date and time

   cout<<"The number of sandwiches"<<setw(20)<<"Total cost"<<setw(20)<<"Total profit"<<endl;

   for(int i=0; i<5; i++)    //This loops on the rows.
        {
            for(int j=0; j<3; j++ ) //This loops on the columns
            {

  array[i][0] = totcount(counter1, counter2, counter3);
                array[i][1] = cost;
                array[i][2] = profit;
            }
             }
         for(int i=0; i<5; i++)    //This loops on the rows.
        {
            for(int j=0; j<3; j++ ) //This loops on the columns
            {
                cout <<setw(20) << array[i][j]  <<setw(15);
            }
            cout << endl;
        }



  //Display the total cost 
        cout<<"Total cost is: "<<cost<<"$"<<endl;

   //Display the total profit
        cout<<"The total profit is: "<<profit<<"$"<<"\n"<<endl;

   if(counter1 != 0) // if counter different than 0
       cout<<counter1 <<". Cheese sandwich(es) "<<sandwichretailprice1<<"$"<<endl;

   if(counter2 != 0) // if counter different than 0
       cout<<counter2 <<". Veggie sandwich(es) "<<sandwichretailprice2<<"$"<<endl;

   if(counter3 != 0) // if counter different than 0
       cout<<counter3 <<". Custom sandwich(es) "<<sandwichretailprice3<<"$"<<endl;

   if(counter1==0 && counter2==0 && counter3==0) // if counter is egale to 0
       cout<<"You did not order anything"<<endl;

   cout<<"\n"<<"Sandwiches total number is "<<t1<<endl;

   cout<<"\n"<<"TOTAL "<<grandtotalinlbp<<" L.L"<<"\n" //display grand total in LBP
           <<"TOTAL "<<grandtotalinusd<<" $"<<endl; //display grand total in USD


   cout<<"\n"<<" if you want to order another delivery press -1"<<endl;
        cin>>repeat;


   }while(repeat == -1 && counter4 < 5);

   if(counter4 == 5)
            {cout<<"You are not allowed to order more than 5 deliveries"<<endl;}



  system("PAUSE");
        return 0; //indicate successful termination
    } //end function main

  int totcount(int count1,int count2,int count3)
    {
    int total;
    total=count1+count2+count3; //calculate the total number of sandwiches 
    return total; 
    } //end function totcount

  void sandtype(int &c1,int &c2,int &c3)
    {
        cout<<"\n"<<"Cheese sandwich "<<c1<<endl;
        cout<<"Veggie sandwich "<<c2<<endl;
        cout<<"Custom sandwich "<<c3<<endl;
    } //end function sandtype

  void profitandcost (double &profit, double &cost, int srp1, int srp2, int srp3, int sc1, int sc2, int sc3, double fc, double dr)
    {
        profit = ((srp1+srp2+srp3)-(sc1+sc2+sc3)-fc-(dr*0.2)); //calculate the total profit
        cost = sc1 + sc2 + sc3 + fc; //calculate the total cost
    } //end function profitandcost
ASSIGNMENT 4

Modify the previous assignment as follows:

Allow the user to input MULTIPLE DELIVERIES, for up to 5 deliveries but possibly fewer.

Keep the functions you wrote in the previous assignment.

FOR EACH DELIVERY: Store the number of sandwiches, total cost, and total profit in a two dimensional array (these values are the results of the functions). The array size should be 5x3, with each row representing a delivery of 1 or more sandwiches.

Finally, display all the details stored in the array in table format. Also display the average delivery cost and average delivery profit (call a function to calculate and return these values. The function takes the array, array size, and a call by reference parameter as arguments. It also returns a double through the return statement).

i started my assignment but it's not workinh like i want
for example if i order 1 sandwiches

the arrays output is 1   2   -1
                     1   2   -1
                     1   2   -1
                     1   2   -1
                     1   2   -1

                     if i order a second one the first order won't stay in memory
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.