473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
//Error 1 error C2601: 'computeBestHot elBestMonth' : 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(i nt[HOTELS][MONTHS]);
int computeYearlyHo telGuest(int[HOTELS][MONTHS]);
int computeBestHote lInAMonth(int totalguests[HOTELS][MONTHS]);
void computeBestHote lBestMonth(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>>totalgu ests[i][j];
int besthotel;
int bestmonth;

displayGuests(t otalguests);
computeYearlyHo telGuest(totalg uests);
computeBestHote lInAMonth(g);
computeBestHote lBestMonth(tota lguests, besthotel, bestmonth);

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

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

cout<<totalgues ts[i][j]<<" ";
cout<<endl;
}

}
int computeYearlyHo telGuest(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<<end l;
}

return 0;
}
int computeBestHote lInAMonth(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 computeBestHote lBestMonth(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
2 1956
prakash ravindran
10 New Member
hi,

The problem is not in the 'computeBestHot elBestMonth' it will work fine. The bug is the 'computeBestHot elInAMonth' function


int computeBestHote lInAMonth(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
thefarmer
55 New Member
//Error 1 error C2601: 'computeBestHot elBestMonth' : 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(i nt[HOTELS][MONTHS]);
int computeYearlyHo telGuest(int[HOTELS][MONTHS]);
int computeBestHote lInAMonth(int totalguests[HOTELS][MONTHS]);
void computeBestHote lBestMonth(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>>totalgu ests[i][j];
int besthotel;
int bestmonth;

displayGuests(t otalguests);
computeYearlyHo telGuest(totalg uests);
computeBestHote lInAMonth(g);
computeBestHote lBestMonth(tota lguests, besthotel, bestmonth);

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

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

cout<<totalgues ts[i][j]<<" ";
cout<<endl;
}

}
int computeYearlyHo telGuest(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<<end l;
}

return 0;
}
int computeBestHote lInAMonth(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 computeBestHote lBestMonth(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<<end l;
}
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

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

Similar topics

9
2034
by: SuSe newbie | last post by:
If someone can help me out with this i would really appreciate it. I'm kind of new so don't bash my code too bad!! This is the error: Parse error: parse error, unexpected T_VARIABLE in /srv/www/htdocs/sendinfo.php on line 45 This is the code: <?php $fname=$_POST; $lname=$_POST; $address=$_POST;
2
3040
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought...
1
1477
by: bigcjr44 | last post by:
I have an assignment do tonite and I can not get it started. We are learning about recursion. This is my assignment, and this is what I have written, could someone please tell me what I am doing wrong.................THANK YOU....... ASSIGNMENT: Demonstrate to the instructor the successful completion of each program output. Have this...
3
17803
by: threepins | last post by:
Hi, Trying the following ... function getCurrentVal(poValue) { var lcCurrentVal = 0; if (isNaN(parseInt(poValue))) { var loValue = poValue.toUpperCase();
6
2864
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or suggestion for improvements or conversion to iteration would be much appreciated
102
5605
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler can't tell where a bracket is missing.... a few weeks have past, I requested a feature for the delphi ide/editor "automatic identation of code in...
4
1253
by: Daniel | last post by:
I would like to get some help on regular expression to validate decimal numbers. It should also match negative value, empty value. The expression: ^(\-){0,1}({1}{0,8}(\,{3})*(\.{0,8})?|{1}{0,}(\.{0,8})?|0(\.{0,8})?|(\.{1,8})?)$ is doing this job, but matches a single hyphen "-" also. For example: matches -12.34 but also matches - I...
2
1800
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about your characters into that save file. Anyhow, I want to extract a couple of lines of it and save it into a database and I need help on figuring...
8
5019
by: Red | last post by:
If auto-format is turned off in VS2008, there is apparently no way to indent a line. Under Tools->Options->Text Editor->C#->Formatting, there are three checkboxes. Unchecking those seems to cause this behavior. I'd simply like to have the tab key insert a tab at the beginning of a line. I believe that there were publlished macros for doing...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.