1

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

#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!!

Votes + Comments
Thanks for using code tags correctly on your first post :)
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

line 88 of the code you posted: You can not code a function inside another function. Write that function outside any other function then just call it on line 88.

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'

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.