| | |
I need help with the errors I developed with C++
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Ok I am trying to write up a data system on C++ so that when i enter in 1-10 i can choose what i want to do....but I keep on getting errors...and the people i already entered in at the bottom (the void add_record) i dont think it correct because there are about 5 of them. please help....the errors will be at the bottom
here are the errors:
1>main.cpp(99) : error C2601: 'add_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(146) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(182) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(216) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(249) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(284) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(318) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(348) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(376) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(444) : error C2084: function 'void add_Record(void)' already has a body
1>main.cpp(14) : see previous definition of 'add_Record'
1>Final Project 1 - 10 error(s), 0 warning(s)
any help would be very nice!!
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <fstream> using namespace std; void DisplayMenu(); int GetChoice(); bool Confirm(); void ProcessChoice(int); int main() { int choice; bool quit = false; do { DisplayMenu(); choice = GetChoice(); if ( choice == 0 ) { if (Confirm()) quit = true; } else ProcessChoice(choice); }while (!quit); return 0; } void DisplayMenu() { cout << "1) Enter new patient\n"; cout << "2) List all smokers\n"; cout << "3) List all Male smokers\n"; cout << "4) List all Female smokers\n"; cout << "5) List all with risk factor greater than 5\n"; cout << "6) List all with risk factor less than 5\n"; cout << "7) Search by SS number\n"; cout << "8) List all by an age\n"; cout << "9) List all with HBP and HFD\n"; cout << "10) List Counts of Smokers, HFD, and HBP\n"; cout << "0) Exit\n"; } int GetChoice() { int choice; cout << " Enter a choice "; cin >> choice; return choice; } bool Confirm() { char choice = 'N'; bool rsp = false; bool done = false; do { cout<<" Are you sure to quit (Y/N)? "; cin >> choice; choice = toupper (choice); if (choice == 'Y') rsp = true; if (choice == 'Y' || choice == 'N') done = true; else done = false; }while (!done); return rsp; } void ProcessChoice(int c) { switch (c) { case 1: void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; cout << "Name: "; cin >> name; cout << "Gender: "; cin >> gender; cout << "Age: "; cin >> age; cout << "SSN: "; cin >> ss; cout << "Smoke: "; cin >> smoke; cout << "HBP (0/1):"; cin >> HBP; cout << "HFD (0/1):"; cin >> HFD; cout << "points (0/1):"; cin >> points; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } break; case 2: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios_base::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout << name <<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (smoke == 1) cout <<"Smoker, "; else cout <<"Non Smoker, "; system ("pause"); } else cout<<"File could not be opened.\n"; inFile.close(); return; } break; case 3: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (smoke ==1 && gender == 'M') cout <<"Smoker, "; else cout <<"Non Smoker, "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 4: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (smoke ==1 && gender == 'F') cout <<"Smoker, "; else cout <<"Non Smoker, "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 5: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (points >= 5) cout <<"Risk Factors Greater Than 5, "; else cout <<"Non Risk Factors Greater Than 5, "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 6: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (points <= 5) cout <<"Risk Factors Less Than 5, "; else cout <<"Non Risk Factors Less Than 5, "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 7: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<"SS# "<<ss<<", "<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 8: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<"Age: "<<age<<", "<<name<<", "<<"Gender: "<<gender<<", "<<"SS# "<<ss<<", "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; case 9: void get_Record() { ifstream inFile; inFile.open ("records.dat", ios::in); string name; char gender; int age; int ss; int smoke; int HBP; int HFD; int points; if (inFile.is_open()) { getline(inFile, name, ','); inFile >> gender >> age >> ss >> smoke >> HBP >> HFD >> points; cout<<name<<", "<<"Gender: "<<gender<<", "<<"Age: "<<age<<", "<<"SS# "<<ss<<", "; if (HBP ==1 && HFD == 1) cout <<"HBP and HFD, "; else cout << "No HBP and HFD, "; system ("pause"); } else cout<<"File could not be opened.\n"; } break; default: cout<<"wrong choice!\n"; } ; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Ms. Johnson"; char gender = 'F' ; int age = 33; int ss = 123456788; int smoke = 0; int HBP = 0; int HFD = 1; int points = 4; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Mr. Kime"; char gender = 'M' ; int age = 19; int ss = 123456888; int smoke = 0; int HBP = 1; int HFD = 1; int points = 4; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Mrs. White"; char gender = 'F' ; int age = 50; int ss = 124356788; int smoke = 0; int HBP = 1; int HFD = 1; int points = 6; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Mr. Long"; char gender = 'M' ; int age = 27; int ss = 121116788; int smoke = 1; int HBP = 1; int HFD = 0; int points = 8; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Mrs. Hughes"; char gender = 'F' ; int age = 43; int ss = 123452768; int smoke = 1; int HBP = 1; int HFD = 1; int points = 10; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; } void add_Record() { ofstream outFile; outFile.open ("records.dat", ios::app); string name = "Ms. Flinstone"; char gender = 'F' ; int age = 17; int ss = 124533248; int smoke = 0; int HBP = 0; int HFD = 1; int points = 2; outFile << name <<","; outFile << gender <<" "; outFile << age <<" "; outFile << ss <<" "; outFile << smoke <<" "; outFile << HBP <<" "; outFile << HFD <<" "; outFile << points << endl; outFile.close(); return; }
here are the errors:
1>main.cpp(99) : error C2601: 'add_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(146) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(182) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(216) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(249) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(284) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(318) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(348) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(376) : error C2601: 'get_Record' : local function definitions are illegal
1>main.cpp(95): this line contains a '{' which has not yet been matched
1>main.cpp(444) : error C2084: function 'void add_Record(void)' already has a body
1>main.cpp(14) : see previous definition of 'add_Record'
1>Final Project 1 - 10 error(s), 0 warning(s)
any help would be very nice!!
Last edited by Ancient Dragon; Jul 4th, 2009 at 9:04 pm. Reason: add line numbers
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Oh ok...I took out the void part of the beginning of the cases and added void get_Record(); and void add_Record(); to the very beginning, but it still left me with the last error:
1>(437) : error C2084: function 'void add_Record(void)' already has a body
1>(7) : see previous definition of 'add_Record'
1>(437) : error C2084: function 'void add_Record(void)' already has a body
1>(7) : see previous definition of 'add_Record'
![]() |
Similar Threads
- J2EE Flow & Errors Clarification (JSP)
- VC++ 6.0 errors (C++)
- Can't change my desktop theme - get rundll32.exe (Viruses, Spyware and other Nasties)
- Simple Programming Errors (Computer Science)
- confused with errors in c++ (C++)
- Loader.EXE and IEDLL.EXE errors (Web Browsers)
- Upgrading Xp Home to Pro - ERRORS! (Windows NT / 2000 / XP)
- strange annoying errors (Windows NT / 2000 / XP)
- w2k server errors (Windows NT / 2000 / XP)
- Two Problems- "Page Cannot Be Displayed" Errors, Z (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: gcc 4.4 In-class member initializers (c++0x)
- Next Thread: need some help with C string
Views: 276 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






