By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

I need help with this error i keep getting about an unmatch brace

P: 2
//Error 1 error C2601: 'computeBestHotelBestMonth' : local function definitions are illegal e:\project 3\prj 3b.cpp 90
//Error 2 fatal error C1075: end of file found before the left brace '{' at 'e:\project 3\prj 3b.cpp(68)' was matched e:\project 3\prj 3b.cpp 104

#include <iostream>
#include <fstream>
using namespace std;
const int HOTELS = 5;
const int MONTHS = 12;
void displayGuests(int[HOTELS][MONTHS]);
int computeYearlyHotelGuest(int[HOTELS][MONTHS]);
int computeBestHotelInAMonth(int totalguests[HOTELS][MONTHS]);
void computeBestHotelBestMonth(int totalguests[HOTELS][MONTHS], int&, int&);

int main ()
{
ifstream infile;//input file object
infile.open("E:\\hoteldata.txt");//open the file
int totalguests[HOTELS][MONTHS];
int g[HOTELS][MONTHS];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 12; j++)
infile>>totalguests[i][j];
int besthotel;
int bestmonth;

displayGuests(totalguests);
computeYearlyHotelGuest(totalguests);
computeBestHotelInAMonth(g);
computeBestHotelBestMonth(totalguests, besthotel, bestmonth);

return 0;
}
void displayGuests(int totalguests[HOTELS][MONTHS])
{

int HOTLES = 5;
int MONTHS = 12;
for (int i=0; i < HOTELS; i++)
{
for (int j=0; j<MONTHS; j++)

cout<<totalguests[i][j]<<" ";
cout<<endl;
}

}
int computeYearlyHotelGuest(int totalguests[HOTELS][MONTHS])
{
int num;
int Hotel;
int Months;
int sum;

cout<<"Enter Hotel number 1 - 5: "<<endl;
cin>>num;
switch(num)
{
case 1:
sum = 0;
Hotel = 1;
for (Months = 0; Months < MONTHS; Months++)
{
sum = sum + totalguests[Hotel][Months];
}
cout<<"Yearly Total: "<<sum<<endl;
}

return 0;
}
int computeBestHotelInAMonth(int totalguests[HOTELS][MONTHS])
{
int month;
int hotel;
int bestHotel;
cout<<"Enter the Month:"<<endl;
cin >> month;

switch (month)
{
case 1:
for (int month = 0; month< MONTHS; month++)
{
bestHotel = totalguests[0][month];
for (hotel = 1; hotel < HOTELS; hotel++)
if (bestHotel < totalguests[hotel][month])
bestHotel = totalguests[hotel][month];

cout<<"The best Hotel in January is"<<bestHotel<<endl;
}
return 0;
}
void computeBestHotelBestMonth(int g[HOTELS][MONTHS],int besthotel, int bestmonth)
{
int goodhotel = 0, goodmonth = 0;
for (int i = 0; i<5; i++)
{
for (int j = 0; j<12; j++)
if(g[goodhotel][goodmonth]<g[i][j])
{
goodhotel = i;
goodmonth = j;
}
}
besthotel = goodhotel + 1;
bestmonth = goodmonth + 1;
}
Dec 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: 10
hi,

The problem is not in the 'computeBestHotelBestMonth' it will work fine. The bug is the 'computeBestHotelInAMonth' function


int computeBestHotelInAMonth(int totalguests[HOTELS][MONTHS])
{
int month;
int hotel;
int bestHotel;
cout<<"Enter the Month:"<<endl;
cin >> month;

switch (month)
{
case 1:
for (int month = 0; month< MONTHS; month++)
{
bestHotel = totalguests[0][month];
for (hotel = 1; hotel < HOTELS; hotel++)
if (bestHotel < totalguests[hotel][month])
bestHotel = totalguests[hotel][month];

cout<<"The best Hotel in January is"<<bestHotel<<endl;
}
return 0;
}


read the code carefully, in this code u had opened a '{' barce for switch statement but that is not closed in right place. So close the brace in correct place that will do....
Dec 18 '06 #2

P: 55
//Error 1 error C2601: 'computeBestHotelBestMonth' : local function definitions are illegal e:\project 3\prj 3b.cpp 90
//Error 2 fatal error C1075: end of file found before the left brace '{' at 'e:\project 3\prj 3b.cpp(68)' was matched e:\project 3\prj 3b.cpp 104

#include <iostream>
#include <fstream>
using namespace std;
const int HOTELS = 5;
const int MONTHS = 12;
void displayGuests(int[HOTELS][MONTHS]);
int computeYearlyHotelGuest(int[HOTELS][MONTHS]);
int computeBestHotelInAMonth(int totalguests[HOTELS][MONTHS]);
void computeBestHotelBestMonth(int totalguests[HOTELS][MONTHS], int&, int&);

int main ()
{
ifstream infile;//input file object
infile.open("E:\\hoteldata.txt");//open the file
int totalguests[HOTELS][MONTHS];
int g[HOTELS][MONTHS];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 12; j++)
infile>>totalguests[i][j];
int besthotel;
int bestmonth;

displayGuests(totalguests);
computeYearlyHotelGuest(totalguests);
computeBestHotelInAMonth(g);
computeBestHotelBestMonth(totalguests, besthotel, bestmonth);

return 0;
}
void displayGuests(int totalguests[HOTELS][MONTHS])
{

int HOTLES = 5;
int MONTHS = 12;
for (int i=0; i < HOTELS; i++)
{
for (int j=0; j<MONTHS; j++)

cout<<totalguests[i][j]<<" ";
cout<<endl;
}

}
int computeYearlyHotelGuest(int totalguests[HOTELS][MONTHS])
{
int num;
int Hotel;
int Months;
int sum;

cout<<"Enter Hotel number 1 - 5: "<<endl;
cin>>num;
switch(num)
{
case 1:
sum = 0;
Hotel = 1;
for (Months = 0; Months < MONTHS; Months++)
{
sum = sum + totalguests[Hotel][Months];
}
cout<<"Yearly Total: "<<sum<<endl;
}

return 0;
}
int computeBestHotelInAMonth(int totalguests[HOTELS][MONTHS])
{
int month;
int hotel;
int bestHotel;
cout<<"Enter the Month:"<<endl;
cin >> month;

switch (month)
{
case 1:
for (int month = 0; month< MONTHS; month++)
{
bestHotel = totalguests[0][month];
for (hotel = 1; hotel < HOTELS; hotel++)
if (bestHotel < totalguests[hotel][month])
bestHotel = totalguests[hotel][month];

cout<<"The best Hotel in January is"<<bestHotel<<endl;
}
return 0;
}
void computeBestHotelBestMonth(int g[HOTELS][MONTHS],int besthotel, int bestmonth)
{
int goodhotel = 0, goodmonth = 0;
for (int i = 0; i<5; i++)
{
for (int j = 0; j<12; j++)
if(g[goodhotel][goodmonth]<g[i][j])
{
goodhotel = i;
goodmonth = j;
}
}
besthotel = goodhotel + 1;
bestmonth = goodmonth + 1;
}


hi there,

i think your error is in within your switch file , co'z you'd always closing it , look at this line:

switch(num)
{
case 1:
sum = 0;
Hotel = 1;
for (Months = 0; Months < MONTHS; Months++)
{
sum = sum + totalguests[Hotel][Months];
}
cout<<"Yearly Total: "<<sum<<endl;
}
return 0;
}

with this line you say that your done already because you'd close the file on your switch case

review your work again and do not close necessary files on your program...

regards,
Dec 18 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.