#pragma once
#include "chartdir.h"
#include <windows.h>
#include "Form1.h"
#include "Form2.h"
#include "Town.h"
#include <iostream>
#include <fstream>
#include <string>

#define NUMBER_OF_AGENTS 16348
#define NUMBER_OF_BARS 255
#define PERCENT_CAPACITY 100
#define MAX_ALPHA 100
#define MAX_AGE 100


namespace BARGAME {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			aa=1;
			bb=1;
			cc=1;
			dd=1;

			ee=0;
			ff=0;
			gg=0;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

		Form^ form2;
		double numagents;
		double numbars;
		
		int percentbarcap1;
		int staticbarcap1;
		int grpsize,avgage,alpha;

	protected: 
	private: System::Windows::Forms::Button^  button1;
	private: int aa,bb,cc,dd,ee,ff,gg;




	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::TextBox^  textBox1;








	private: System::Windows::Forms::RadioButton^  radioButton1;


	private: System::Windows::Forms::TextBox^  textBox5;


	private: System::Windows::Forms::CheckBox^  checkBox1;

	private: System::Windows::Forms::CheckBox^  checkBox3;





	private: System::Windows::Forms::HelpProvider^  helpProvider1;



	private: System::Windows::Forms::Label^  label5;

	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::TextBox^  textBox2;


	private: System::Windows::Forms::TextBox^  textBox4;
	private: System::Windows::Forms::ErrorProvider^  errorProvider1;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::TextBox^  textBox8;
	private: System::Windows::Forms::Button^  button2;





	private: System::ComponentModel::IContainer^  components;




	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
			this->textBox5 = (gcnew System::Windows::Forms::TextBox());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox3 = (gcnew System::Windows::Forms::CheckBox());
			this->helpProvider1 = (gcnew System::Windows::Forms::HelpProvider());
			this->textBox4 = (gcnew System::Windows::Forms::TextBox());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->errorProvider1 = (gcnew System::Windows::Forms::ErrorProvider(this->components));
			this->textBox8 = (gcnew System::Windows::Forms::TextBox());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->button2 = (gcnew System::Windows::Forms::Button());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->errorProvider1))->BeginInit();
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(224)), static_cast<System::Int32>(static_cast<System::Byte>(224)), 
				static_cast<System::Int32>(static_cast<System::Byte>(224)));
			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button1->ForeColor = System::Drawing::SystemColors::ControlText;
			this->button1->Location = System::Drawing::Point(473, 101);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(214, 90);
			this->button1->TabIndex = 2;
			this->button1->Text = L"Simulate";
			this->button1->UseVisualStyleBackColor = false;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::Color::Transparent;
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label1->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->label1->Location = System::Drawing::Point(12, 35);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(212, 29);
			this->label1->TabIndex = 9;
			this->label1->Text = L"Number of Agents:";
			this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
			// 
			// textBox1
			// 
			this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox1->Location = System::Drawing::Point(230, 35);
			this->textBox1->Name = L"textBox1";
			this->textBox1->RightToLeft = System::Windows::Forms::RightToLeft::No;
			this->textBox1->Size = System::Drawing::Size(131, 26);
			this->textBox1->TabIndex = 10;
			this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox1->Validating += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::textBox1_Validating);
			// 
			// radioButton1
			// 
			this->radioButton1->AutoSize = true;
			this->radioButton1->BackColor = System::Drawing::Color::Transparent;
			this->radioButton1->Checked = true;
			this->radioButton1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->radioButton1->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->radioButton1->Location = System::Drawing::Point(-14, 159);
			this->radioButton1->Name = L"radioButton1";
			this->radioButton1->Size = System::Drawing::Size(215, 33);
			this->radioButton1->TabIndex = 19;
			this->radioButton1->TabStop = true;
			this->radioButton1->Text = L"Grouper Percent:";
			this->radioButton1->UseVisualStyleBackColor = false;
			this->radioButton1->CheckedChanged += gcnew System::EventHandler(this, &Form1::radioButton1_CheckedChanged);
			// 
			// textBox5
			// 
			this->textBox5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox5->Location = System::Drawing::Point(230, 165);
			this->textBox5->Name = L"textBox5";
			this->textBox5->RightToLeft = System::Windows::Forms::RightToLeft::No;
			this->textBox5->Size = System::Drawing::Size(131, 26);
			this->textBox5->TabIndex = 22;
			this->textBox5->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox5->TextChanged += gcnew System::EventHandler(this, &Form1::textBox5_TextChanged);
			this->textBox5->Validating += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::textBox5_Validating);
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->BackColor = System::Drawing::Color::Transparent;
			this->checkBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->checkBox1->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->checkBox1->Location = System::Drawing::Point(16, 253);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(122, 33);
			this->checkBox1->TabIndex = 25;
			this->checkBox1->Text = L"Mortality";
			this->checkBox1->UseVisualStyleBackColor = false;
			this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged_1);
			// 
			// checkBox3
			// 
			this->checkBox3->AutoSize = true;
			this->checkBox3->BackColor = System::Drawing::Color::Transparent;
			this->checkBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->checkBox3->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->checkBox3->Location = System::Drawing::Point(16, 120);
			this->checkBox3->Name = L"checkBox3";
			this->checkBox3->Size = System::Drawing::Size(118, 33);
			this->checkBox3->TabIndex = 27;
			this->checkBox3->Text = L"Herding";
			this->checkBox3->UseVisualStyleBackColor = false;
			this->checkBox3->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox3_CheckedChanged_1);
			// 
			// helpProvider1
			// 
			this->helpProvider1->HelpNamespace = L"C:\\Users\\Andrew\\Documents\\Visual Studio 2010\\Projects\\BARGAME\\BARGAMEhelp.CHM";
			// 
			// textBox4
			// 
			this->textBox4->Enabled = false;
			this->textBox4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox4->Location = System::Drawing::Point(230, 212);
			this->textBox4->Name = L"textBox4";
			this->textBox4->Size = System::Drawing::Size(131, 26);
			this->textBox4->TabIndex = 28;
			this->textBox4->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox4->Validating += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::textBox4_Validating);
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->BackColor = System::Drawing::Color::Transparent;
			this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label5->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->label5->Location = System::Drawing::Point(7, 305);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(215, 29);
			this->label5->TabIndex = 34;
			this->label5->Text = L"Average Life Span:";
			this->label5->Click += gcnew System::EventHandler(this, &Form1::label5_Click);
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->BackColor = System::Drawing::Color::Transparent;
			this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label3->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->label3->Location = System::Drawing::Point(7, 212);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(217, 29);
			this->label3->TabIndex = 32;
			this->label3->Text = L"Number of Groups:";
			this->label3->Click += gcnew System::EventHandler(this, &Form1::label3_Click);
			// 
			// textBox2
			// 
			this->textBox2->Enabled = false;
			this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox2->Location = System::Drawing::Point(230, 308);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(131, 26);
			this->textBox2->TabIndex = 31;
			this->textBox2->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox2->TextChanged += gcnew System::EventHandler(this, &Form1::textBox2_TextChanged);
			this->textBox2->Validating += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::textBox2_Validating);
			// 
			// errorProvider1
			// 
			this->errorProvider1->BlinkStyle = System::Windows::Forms::ErrorBlinkStyle::NeverBlink;
			this->errorProvider1->ContainerControl = this;
			// 
			// textBox8
			// 
			this->textBox8->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox8->Location = System::Drawing::Point(624, 308);
			this->textBox8->Name = L"textBox8";
			this->textBox8->RightToLeft = System::Windows::Forms::RightToLeft::No;
			this->textBox8->Size = System::Drawing::Size(121, 26);
			this->textBox8->TabIndex = 32;
			this->textBox8->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->BackColor = System::Drawing::Color::Transparent;
			this->label6->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label6->ForeColor = System::Drawing::SystemColors::ButtonHighlight;
			this->label6->Location = System::Drawing::Point(411, 308);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(208, 29);
			this->label6->TabIndex = 34;
			this->label6->Text = L"Output File Name:";
			// 
			// button2
			// 
			this->button2->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(224)), static_cast<System::Int32>(static_cast<System::Byte>(224)), 
				static_cast<System::Int32>(static_cast<System::Byte>(224)));
			this->button2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button2->Location = System::Drawing::Point(286, 351);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(75, 34);
			this->button2->TabIndex = 35;
			this->button2->Text = L"Clear";
			this->button2->UseVisualStyleBackColor = false;
			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::SystemColors::ButtonFace;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(797, 397);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->radioButton1);
			this->Controls->Add(this->label6);
			this->Controls->Add(this->textBox5);
			this->Controls->Add(this->textBox8);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->textBox2);
			this->Controls->Add(this->button1);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->checkBox3);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->textBox4);
			this->Controls->Add(this->checkBox1);
			this->HelpButton = true;
			this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"Form1";
			this->helpProvider1->SetShowHelp(this, true);
			this->Text = L"MINORITYGAME";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->errorProvider1))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
			 //Simulate button.  Takes in the user's input and creates the next window.
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 numagents = (double) Int32::Parse(textBox1->Text);
				 
				 numbars = 1;
				 alpha = -1;
				 //checks to see if data exists for certain options
				 if(checkBox3->Checked==true){
					 grpsize = Int32::Parse(textBox4->Text);
				 }
				 else if(checkBox3->Checked==false){
					 grpsize=1;
				 }
				 /*if(checkBox2->Checked==true){
					 alpha = -1;
				 }
				 else if(checkBox2->Checked==false){
					 alpha=-1;
				 }*/
				 if(checkBox1->Checked==true){
					 avgage = Int32::Parse(textBox2->Text);
				 }
				 else if(checkBox1->Checked==false){
					 avgage=-1;
				 }

				 //tokenizer for percentbarcap
				 if(radioButton1->Checked==true)
				 {
					 String^ delimStr = " ,.:\t";
					 array<Char>^ delimiter = delimStr->ToCharArray( );
					 array<String^>^ words;
					 String^ line = textBox5->Text;
					 words = line->Split( delimiter );
					 //percentbarcap1=new int[numbars];

					 //If one number was inputted for the capacity, and number of bars is bigger than one, then duplicate
					 //that number and set it as the capacity for all bars.
					/* if(words->Length==1 && numbars!=1){
						 for (int word=0; word<numbars; word++){
							 percentbarcap1 = (double) Int32::Parse(words[0]);
						 }
					 }
					 else{
						 for (int word=0; word<numbars; word++){
							 //percentbarcap1[word]= (double) Int32::Parse(words[word]);	//ΈΔΑΛ
							 percentbarcap1 = (double) Int32::Parse(words[word]);
						 }
					 }*/
					 /**/
					 if (textBox5 -> Text == "")
						percentbarcap1 = 0;
					 else 
						 percentbarcap1 = Int32::Parse(textBox5->Text);


					 //Creates new windows using percent capacity
					 form2 = gcnew Form2(numagents,percentbarcap1,true,avgage,alpha,grpsize,textBox8->Text);
					 form2 ->ShowDialog();
				 }
				 /*
				 else	//tokenizer for staticbarcap
				 {
					 
					 String^ delimStr = " ,.:\t";
					 array<Char>^ delimiter = delimStr->ToCharArray( );
					 array<String^>^ words;
					 String^ line = textBox6->Text;
					 words = line->Split( delimiter );
					 staticbarcap1=new int[numbars];

					 if(words->Length==1 && numbars!=1){
						 for (int word=0; word<numbars; word++){
							 staticbarcap1[word] = (double) Int32::Parse(words[0]);
						 }
					 }
					 else{
						 for (int word=0; word<numbars; word++){
							 staticbarcap1[word] = (double) Int32::Parse(words[word]);
						 }
					 }

					 //Creates new windows using static capacity
					 form2 = gcnew Form2(numagents,staticbarcap1,false,avgage,alpha,textBox8->Text);
					 form2 ->ShowDialog();
				 }*/

			 }



	private: System::Void radioButton1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				 textBox5->Enabled=true;
				 /*textBox6->Enabled=false;*/
				 errorProvider1->SetError(textBox5, "");
			 }
	/*private: System::Void radioButton2_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				 textBox5->Enabled=false;
				 textBox6->Enabled=true;
				 errorProvider1->SetError(textBox6, "");
			 }*/

			 //Error handling for number of agents input
	private: System::Void textBox1_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 try
				 {
					 int x = Int32::Parse(textBox1->Text);
					 errorProvider1->SetError(textBox1, "");
					 aa=0;
					 if(radioButton1->Checked==true){
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 if(x>NUMBER_OF_AGENTS || x<1){
						 button1->Enabled=false;
						 errorProvider1->SetError(textBox1, "Please enter an integer between 1 and 16,348");
						 aa=1;
					 }
				 }
				 catch (System::Exception ^ ex)
				 {
					 button1->Enabled=false;
					 errorProvider1->SetError(textBox1, "Please enter an integer between 1 and 16,348");
					 aa=1;
				 }
			 }
			 //Error handling for number of bars input
	
			
	private: System::Void textBox5_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 try
				 {
					 double numbars = 1;
					 String^ delimStr = " ,.:\t";
					 array<Char>^ delimiter = delimStr->ToCharArray();
					 array<String^>^ words;
					 String^ line = textBox5->Text;
					 words = line->Split( delimiter );
					 for (int word=0; word<words->Length; word++){
						 int x = Int32::Parse(words[word]);
					 }
					 errorProvider1->SetError(textBox5, "");
					 cc=0;
					 if(radioButton1->Checked==true){
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 for (int word=0; word<words->Length; word++){
						 int x = Int32::Parse(words[word]);
						 if(x>PERCENT_CAPACITY || x<1 || (words->Length>1 && words->Length<numbars) || (words->Length>1 && words->Length>numbars) ){
							 button1->Enabled=false;
							 errorProvider1->SetError(textBox5, "Please enter integers between 1 and 100 seperated by either a \" \", \",\", \":\", or \".\"");
							 cc=1;
						 }
					 }
				 }
				 catch (System::Exception ^ ex)			//here!!!!!!!!!!!!!!!!!!!!!!!!
				 {
					 button1->Enabled=false;
					 errorProvider1->SetError(textBox5, "Please enter integers between 1 and 100 seperated by either a \" \", \",\", \":\", or \".\"");
					 cc=1;
				 }
			 }
			 //Error handling for static capacity input
	/*private: System::Void textBox6_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 try
				 {
					 double numbars = 1;
					 String^ delimStr = " ,.:\t";
					 array<Char>^ delimiter = delimStr->ToCharArray( );
					 array<String^>^ words;
					 String^ line = textBox6->Text;
					 words = line->Split( delimiter );
					 for (int word=0; word<words->Length; word++){
						 int x = Int32::Parse(words[word]);
					 }
					 errorProvider1->SetError(textBox6, "");
					 dd=0;
					 if(radioButton1->Checked==true){
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 for (int word=0; word<words->Length; word++){
						 int x = Int32::Parse(words[word]);
						 if(x>numagents || x<1 || (words->Length>1 && words->Length<numbars) || (words->Length>1 && words->Length>numbars) ){
							 button1->Enabled=false;
							 errorProvider1->SetError(textBox6, "Please enter integers between 1 and 16,348 seperated by either a \" \", \",\", \":\", or \".\"");
							 dd=1;
						 }
					 }
				 }
				 catch (System::Exception ^ ex)
				 {
					 button1->Enabled=false;
					 errorProvider1->SetError(textBox6, "Please enter integers between 1 and 16,348 seperated by either a \" \", \",\", \":\", or \".\"");
					 dd=1;
				 }
			 }
			 //Error handling for group size input*/
	private: System::Void textBox4_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 
				 try
				 {
					 int maxgroupsize=Int32::Parse(textBox1->Text)/(2);
					 int x = Int32::Parse(textBox4->Text);
					 
					 errorProvider1->SetError(textBox4, "");
					 ee=0;
					 if(radioButton1->Checked==true){
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 if(x>maxgroupsize || x<1){
						 errorProvider1->SetError(textBox4, "Please enter an integer between 1 and "+maxgroupsize);
						 button1->Enabled=false;
						 ee=1;
					 }
				 }
				 catch (System::Exception ^ ex)
				 {
					 errorProvider1->SetError(textBox4, "Please first input an integer for the number of agents and bar options");
					 button1->Enabled=false;
					 ee=1;
				 }
			 }
			 //Error handling for alpha input
	/*private: System::Void textBox7_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 try
				 {
					 int x = Int32::Parse(textBox7->Text);
					 ff=0;
					 errorProvider1->SetError(textBox7, "");
					 if(radioButton1->Checked==true){
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 if(x>MAX_ALPHA || x<1){
						 errorProvider1->SetError(textBox7, "Please enter an integer between 1 and 100");
						 button1->Enabled=false;
						 ff=1;
					 }
				 }
				 catch (System::Exception ^ ex)
				 {
					 errorProvider1->SetError(textBox7, "Please enter an integer between 1 and 100");
					 button1->Enabled=false;
					 ff=1;
				 }
			 }
			 //Error handling for average age input*/
	private: System::Void textBox2_Validating(System::Object ^  sender, System::ComponentModel::CancelEventArgs ^  e) {
				 try
				 {
					 int x = Int32::Parse(textBox2->Text);
					 gg=0;
					 errorProvider1->SetError(textBox2, "");
					 if(radioButton1->Checked==true)
					 {
						 if (!(aa+bb+cc+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 else{
						 if (!(aa+bb+dd+ee+ff+gg)){
							 button1->Enabled=true;
						 }
					 }
					 if(x>MAX_AGE || x<1){
						 errorProvider1->SetError(textBox2, "Please enter an integer between 1 and 100");
						 button1->Enabled=false;
						 gg=1;
					 }
				 }
				 catch (System::Exception ^ ex)
				 {
					 errorProvider1->SetError(textBox2, "Please enter an integer between 1 and 100");
					 button1->Enabled=false;
					 gg=1;
				 }
			 }
	private: System::Void checkBox3_CheckedChanged_1(System::Object^  sender, System::EventArgs^  e) {
				 if(checkBox3->Checked==true){
					 textBox4->Enabled=true;
				 }
				 else{
					 textBox4->Enabled=false;
					 errorProvider1->SetError(textBox4, "");
					 ee=0;

				 }
			 }
	
	private: System::Void checkBox1_CheckedChanged_1(System::Object^  sender, System::EventArgs^  e) {
				 if(checkBox1->Checked==true){
					 textBox2->Enabled=true;
				 }
				 else{
					 textBox2->Enabled=false;
					 errorProvider1->SetError(textBox2, "");
					 gg=0;
				 }
			 }
	
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox5_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void textBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void label3_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
/*private: System::Void textBox6_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }*/
private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void label5_Click(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
			  button1->Enabled=true;
			  textBox1->Text = "";
			  textBox2->Text = "";
			  
			  textBox4->Text = "";
			  textBox5->Text = "";
			  textBox8->Text = "";
		 }
		 

};
}