I'm supposed to create a bill for a catering group utilizing at least two functions, which functions could I use for this and how will I use them? I've done it with mainly if and else statements and simple calculations, any functions I can use?

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
    int adults;
    int children;
    double ameals;
    double cmeals;
    char mealtype;
    char weekend;
    string mealtype2;
    double deposit;
    double dmeals=15.80;
    double smeals=11.75;
    double foodtotal;
    double surcharge;
    double totalbill;
    double discount;
    double taxtip;

    cout<<"How many adults? ";
    cin>>adults;
    cout<<"How many children? ";
    cin>>children;
    cout<<"Deluxe meals or standard meals? (D/S) ";
    cin>>mealtype;
    cout<<"Weekend? (Y/N) ";
    cin>>weekend;
    cout<<"Deposit amount: ";
    cin>>deposit;
    {
    if (mealtype=='D')
    foodtotal=dmeals*adults+dmeals*0.6*children;
    ameals=dmeals*adults;
    cmeals=dmeals*0.6*children;
    mealtype2="Deluxe";
    if (mealtype=='S')
    foodtotal=smeals*adults+smeals*0.6*children;
    ameals=dmeals*adults;
    cmeals=dmeals*0.6*children;
    mealtype2="Standard";
    }
    taxtip=0.18*foodtotal;
    totalbill=foodtotal+taxtip;
    if (weekend=='Y')
    {
    surcharge=totalbill*0.07;
    totalbill=totalbill+surcharge;
    }
    else 
        surcharge=0;
    if (totalbill<100)
            discount=totalbill*0.015;
        else if (totalbill>=100 && totalbill<400)
            discount=totalbill*0.025;
        else
            discount=totalbill*0.035;
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"Number of adults: \t"<<adults<<setw(7)<<endl;
    cout<<"Number of children: \t"<<children<<setw(7)<<endl;
    cout<<"Meal Type: \t\t"<<mealtype2<<setw(7)<<endl;
    cout<<"Adult meal cost:\t"<<ameals<<setw(7)<<endl;
    cout<<"Children meal cost:\t"<<cmeals<<setw(7)<<endl;
    cout<<"Surcharge: \t\t"<<surcharge<<setw(7)<<endl;
    cout<<"Tax and Tip: \t\t"<<taxtip<<setw(7)<<endl;
    cout<<"Deposit: \t\t"<<deposit<<setw(7)<<endl;
    cout<<"Total Balance Due: \t"<<totalbill<<setw(7)<<endl;
    cout<<"Discount: \t\t"<<discount<<setw(7)<<endl;

    return 0;

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Please use Code Tags

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

double catererCal(); //function declration
double discountCal(); //functin declaration
void printBill(); //function declaration

int adults;
int children;
double ameals;
double cmeals;
char mealtype;
char weekend;
string mealtype2;
double deposit;
double dmeals=15.80;
double smeals=11.75;
double foodtotal;
double surcharge;
double totalbill;
double discount;
double taxtip;

int main()
{
cout<<"How many adults? ";
cin>>adults;
cout<<"How many children? ";
cin>>children;
cout<<"Deluxe meals or standard meals? (D/S) ";
cin>>mealtype;
cout<<"Weekend? (Y/N) ";
cin>>weekend;
cout<<"Deposit amount: ";
cin>>deposit;
catererCal(); //function call
discountCal(); //function call
printBill(); //function call
system("pause");
return 0;
}

double catererCal() //function declarator
{
if(mealtype=='D')
{
foodtotal=dmeals*adults+dmeals*0.6*children;
ameals=dmeals*adults;
cmeals=dmeals*0.6*children; 
mealtype2="Deluxe"; //function body
}
if (mealtype=='S')
{
foodtotal=smeals*adults+smeals*0.6*children;
ameals=dmeals*adults;
cmeals=dmeals*0.6*children;
mealtype2="Standard";
}
taxtip=0.18*foodtotal;
totalbill=foodtotal+taxtip;
return 0;
}

double discountCal() //function declarator
{
if (weekend=='Y')
{
surcharge=totalbill*0.07;
totalbill=totalbill+surcharge;
}
else
{ 
surcharge=0; // function body
}
if (totalbill<100)
discount=totalbill*0.015;
else if (totalbill>=100 && totalbill<400)
discount=totalbill*0.025;
else
discount=totalbill*0.035;
return 0;
}

void printBill() //function declarator
{
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Number of adults: \t"<<adults<<setw(7)<<endl;
cout<<"Number of children: \t"<<children<<setw(7)<<endl;
cout<<"Meal Type: \t\t"<<mealtype2<<setw(7)<<endl;
cout<<"Adult meal cost:\t"<<ameals<<setw(7)<<endl;
cout<<"Children meal cost:\t"<<cmeals<<setw(7)<<endl;
cout<<"Surcharge: \t\t"<<surcharge<<setw(7)<<endl; //function body
cout<<"Tax and Tip: \t\t"<<taxtip<<setw(7)<<endl;
cout<<"Deposit: \t\t"<<deposit<<setw(7)<<endl;
cout<<"Total Balance Due: \t"<<totalbill<<setw(7)<<endl;
cout<<"Discount: \t\t"<<discount<<setw(7)<<endl;
}

that seems to work, and one more thing, how will I tell it not to display surcharge when it's not a weekend and and not to display deposit when there's no money deposited?

There could be various approaches but the quickest to me is

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;

double catererCal();
double discountCal();
void printBill();

int adults;
int children;
double ameals;
double cmeals;
char mealtype;
char weekend;
string mealtype2;
double deposit;
double dmeals=15.80;
double smeals=11.75;
double foodtotal;
double surcharge;
double totalbill;
double discount;
double taxtip;

int main()
{
cout<<"How many adults? ";
cin>>adults;
cout<<"How many children? ";
cin>>children;
cout<<"Deluxe meals or standard meals? (D/S) ";
cin>>mealtype;
cout<<"Weekend? (Y/N) ";
cin>>weekend;
cout<<"Deposit amount: ";
cin>>deposit;
catererCal();
discountCal();
printBill();
system("pause");
return 0;
}

double catererCal()
{
if(mealtype=='D')
{
foodtotal=dmeals*adults+dmeals*0.6*children;
ameals=dmeals*adults;
cmeals=dmeals*0.6*children;
mealtype2="Deluxe";
}
if (mealtype=='S')
{
foodtotal=smeals*adults+smeals*0.6*children;
ameals=dmeals*adults;
cmeals=dmeals*0.6*children;
mealtype2="Standard";
}
taxtip=0.18*foodtotal;
totalbill=foodtotal+taxtip;
return totalbill;
return 0;
}

double discountCal()
{
if (weekend=='Y')
{
surcharge=totalbill*0.07;
totalbill=totalbill+surcharge;
}
else
{ 
surcharge=0;
}
if (totalbill<100)
discount=totalbill*0.015;
else if (totalbill>=100 && totalbill<400)
discount=totalbill*0.025;
else
discount=totalbill*0.035;
return discount;
return 0;
}

void printBill()
{	
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Number of adults: \t"<<adults<<setw(7)<<endl;
cout<<"Number of children: \t"<<children<<setw(7)<<endl;
cout<<"Meal Type: \t\t"<<mealtype2<<setw(7)<<endl;
cout<<"Adult meal cost:\t"<<ameals<<setw(7)<<endl;
cout<<"Children meal cost:\t"<<cmeals<<setw(7)<<endl;
if (weekend=='Y')
cout<<"Surcharge: \t\t"<<surcharge<<setw(7)<<endl;
else
cout<<"Tax and Tip: \t\t"<<taxtip<<setw(7)<<endl;
if (deposit!=0)
cout<<"Deposit: \t\t"<<deposit<<setw(7)<<endl;
else
cout<<"Total Balance Due: \t"<<totalbill<<setw(7)<<endl;
cout<<"Discount: \t\t"<<discount<<setw(7)<<endl;
}
This question has already been answered. Start a new discussion instead.