can't seem to get the value-returning function right...

I haven't finished my program yet, but the errors say, "local function definitions are illegal" for my functions...I don't know what to do, does anyone have any suggestions? Thanks



#include <iostream>
#include <fstream>
using namespace std;
char mealType (char);
double mealCost (double adultMeal,double childMeal);
double TaxTip (double mealCost);
double Bill (double, double);

int main()
{
int numAdults, numChildren;
double childMeal, adultMeal;
char type;
char weekend;

ifstream infile;
ofstream outfile;
infile.open("C:\\TEMP\\cateringdata.txt");
if(!infile)
{cout<<"File not found."<<endl;
outfile<<"Program terminates.";
exit(1);
}
outfile.open("C:\\TEMP\\outCatering.txt");
while(!infile.eof())
{
infile>>numAdults>>numChildren;
if( numAdults && numChildren <=0)
{outfile<<"# of Adults : Number of guests is invalid."<<endl;
outfile<<" # of Children: Number of guests is invalid."<<endl;}
else
outfile<<"# of Adults :"<<numAdults<<endl;
outfile<<"# of Children:"<<numChildren<<endl;
infile>>type;



double mealCost(double adultMeal, double childMeal)
{ mealCost=((adultMeal * numAdults)+ (childMeal * numChildren));
outfile<<"Total Meal Cost:"<<mealCost<<endl;}
double TaxTip(double mealCost)
{TaxTip=(mealCost*(.18));
outfile<<"Tax and Tip:"<<TaxTip<<endl;}
double Bill(double mealCost, double TaxTip)
{Bill= mealCost+TaxTip;
outfile<<"Bill: "<<Bill<<endl;}



char mealType( char type);
{ if (type == 'D' || 'd')

{adultMeal= 15.80;
childMeal= (.6 * 15.80);
outfile<<"Meal Type: Deluxe"<<endl;
outfile<<"Adult Meal Cost:"<<adultMeal*numAdults<<endl;
outfile<<"Children Meal Cost:"<<childMeal*numChildren<<endl;}

else if (type == 'S' || 's')
{adultMeal = 11.75;
childMeal = (.6 * 11.75);
outfile<<"Meal Type: Standard"<<endl;}

else outfile<<"Meal Type: Unidentified"<<endl;}


infile.close();
outfile.close();
return 0;
}
}
Firstly please use [code*] and [/code*] tags (remove asterisk):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <fstream>
using namespace std;
char mealType (char);
double mealCost (double adultMeal,double childMeal);
double TaxTip (double mealCost);
double Bill (double, double);

int main()
{
int numAdults, numChildren;
double childMeal, adultMeal;
char type;
char weekend;

ifstream infile;
ofstream outfile;
infile.open("C:\\TEMP\\cateringdata.txt");
if(!infile)
{cout<<"File not found."<<endl;
outfile<<"Program terminates.";
exit(1);
}
outfile.open("C:\\TEMP\\outCatering.txt");
while(!infile.eof())
{
infile>>numAdults>>numChildren;
if( numAdults && numChildren <=0)
{outfile<<"# of Adults : Number of guests is invalid."<<endl;
outfile<<" # of Children: Number of guests is invalid."<<endl;}
else
outfile<<"# of Adults :"<<numAdults<<endl;
outfile<<"# of Children:"<<numChildren<<endl;
infile>>type;



double mealCost(double adultMeal, double childMeal)
{ mealCost=((adultMeal * numAdults)+ (childMeal * numChildren));
outfile<<"Total Meal Cost:"<<mealCost<<endl;}
double TaxTip(double mealCost)
{TaxTip=(mealCost*(.18));
outfile<<"Tax and Tip:"<<TaxTip<<endl;}
double Bill(double mealCost, double TaxTip)
{Bill= mealCost+TaxTip;
outfile<<"Bill: "<<Bill<<endl;}



char mealType( char type);
{ if (type == 'D' || 'd')

{adultMeal= 15.80;
childMeal= (.6 * 15.80);
outfile<<"Meal Type: Deluxe"<<endl;
outfile<<"Adult Meal Cost:"<<adultMeal*numAdults<<endl;
outfile<<"Children Meal Cost:"<<childMeal*numChildren<<endl;}

else if (type == 'S' || 's')
{adultMeal = 11.75;
childMeal = (.6 * 11.75);
outfile<<"Meal Type: Standard"<<endl;}

else outfile<<"Meal Type: Unidentified"<<endl;}


infile.close();
outfile.close();
return 0;
}
}

I think the problem is this part:
1
2
3
4
5
6
7
8
9
double mealCost(double adultMeal, double childMeal)
{ mealCost=((adultMeal * numAdults)+ (childMeal * numChildren));
outfile<<"Total Meal Cost:"<<mealCost<<endl;}
double TaxTip(double mealCost)
{TaxTip=(mealCost*(.18));
outfile<<"Tax and Tip:"<<TaxTip<<endl;}
double Bill(double mealCost, double TaxTip)
{Bill= mealCost+TaxTip;
outfile<<"Bill: "<<Bill<<endl;}

Perhaps it should be this:
1
2
3
4
5
6
7
8
9
10
double adultMeal, childMeal;
double mealCost(adultMeal, childMeal);
{ mealCost=((adultMeal * numAdults)+ (childMeal * numChildren));
outfile<<"Total Meal Cost:"<<mealCost(adultMeal, childMeal)<<endl;}
double TaxTip(double mealCost)
{TaxTip=(mealCost*(.18));
outfile<<"Tax and Tip:"<<TaxTip<<endl;}
double Bill(double mealCost, double TaxTip)
{Bill= mealCost+TaxTip;
outfile<<"Bill: "<<Bill<<endl;}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;


int main()
{

double calcAdultcost(int& numAdults, char& type, double adultMealcost);
double calcChildcost(int& numChildren, char& type, double childMealcost);
double mealcost(double& adultMealcost,double& childMealcost);

int numAdults, numChildren;
char type;
float deposit;
char weekend;

ifstream infile;
ofstream outfile;

infile.open("C:\\Users\\Piya\\Desktop\\cateringdata.txt");

if(!infile)
{cout<<"File not found."<<endl;
outfile<<"Program terminates.";
return 1;}

outfile.open("C:\\Users\\Piya\\Desktop\\outCatering.txt");


while(!infile.eof())

{
	cout<<"\t\tGourmet Catering Group Bill:\t\t"<<endl<<endl;
		infile>>numAdults;	
		cout<<"Adults:\t\t "<<numAdults<<endl;
		infile>>numChildren;
		cout<<"Children:\t  "<<numChildren<<endl;
		
		if(numChildren&&numAdults ==0)
		{cout<<"Error in number of guests."<<endl;
		return 1;}

		infile>>type;
		cout<<"Meal Type:\t  "<<type<<endl;

double calcAdultcost(int& numAdults,char& type,double adultMealcost);
double calcChildcost(int& numChildren, char& type, double childMealcost);

		cout<<"Adult Meal Cost:"<<adultMealcost<<endl;
		cout<<"Child Meal Cost:"<<childMealcost<<endl;

		infile>>weekend;
		cout<<"Weekend:\t  "<<weekend<<endl;
		infile>>deposit;
		cout<<"Deposit:\t"<<deposit<<endl;



	

	infile.close();
outfile.close();
return 0;}
}

double calcAdultcost(int& numAdults, char& type, double adultMealcost)
{
if (numAdults<0)
{cout<<"Error in number of adults."<<endl;
return 1;}

if (type == 'S')
{adultMealcost=(numAdults*(11.75));}


if (type=='D')
{adultMealcost=(numAdults*(15.80));}

else 
{cout<<"Error in type of meal."<<endl;
return 1;}
}

double calcChildcost(int& numChildren, char& type, double childMealcost)
{
if (numChildren<0)
{cout<<"Error in number of children."<<endl;
return 1;}

if (type == 'S')
{childMealcost=(numChildren*((.6)*(11.75)));}

if (type=='D')
{childMealcost=(numChildren*((.6)*15.80));}

else 
{cout<<"Error in type of meal."<<endl;
return 1;}
}


When I tried to debug it, I got these two errors that I can't figure out where the problem is:

1
2
1>c:\desktop\cateringlab6\cateringlab6\lab6.cpp(51) : error C2065: 'adultMealcost' : undeclared identifier
1>c:\desktop\cateringlab6\cateringlab6\lab6.cpp(52) : error C2065: 'childMealcost' : undeclared identifier


Any help would be much appreciated, thank you!
You have some newbie mistakes...read:

http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.