• Advertisement

Archived

This topic is now archived and is closed to further replies.

Check Program

This topic is 5592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I compile the following program the compiler indicates that there is no errors, but when I run the program I get an error. Try to run tis program with "system 12" that means enter "0":
  
#include <iostream>
#include <vector>

using namespace std;

class Tips
{
public:
	void FindTipsSystem();						// OK

	void SetTips12();							// OK

	void SetTips13();							// OK

	void SetActiveTips(short);					// OK

	void CheckTips(short sys);					// OK

	short GetSystem() { return sys_type; }		// OK


private:
	short rows;
	char** rows_interactive;
	char* match_active_results;
	short sys_type;
	int* corr_array;
};

void Tips::FindTipsSystem()
{
	cout << "What system (12/13)?\n12: \"0\"\n13: \"1\"\n> ";
	cin >> rows;

	switch (rows)
	{
	case 0: cout << "\t\t-- System is Tips 12 --" << endl;
		sys_type = 12;
		SetActiveTips(sys_type);
		SetTips12();
		break;
	case 1: cout << "\t\t-- System is Tips 13 --" << endl;
		sys_type = 13;
		SetActiveTips(sys_type);
		SetTips13();
		break;
	default: cout << "Bool-value error!" << endl;
		FindTipsSystem();
	}
}

void Tips::SetActiveTips(short sys_type)
{
	match_active_results = new char[13];
	for (int i = 0; i < sys_type; i++)
	{
		cout << i+1 << ": ";
		cin >> match_active_results[i];
	}
}

void Tips::SetTips12()
{
	cout << "How many rows? " << endl;
	cin >> rows;
	if (rows > 0)
	{
		//rows_interactive = new char*[rows];

		//rows_interactive = new char[12];

		std::vector< std::vector<char> > rows_interactive( rows, std::vector<char>( 12 ) );

		for(int i = 0; i < rows; i++)
		{
			cout << "Row " << i+1 << ": " << endl;
			for (int j = 0; j < 12; j++)
			{

				cout << j+1 << ": ";
				cin >> rows_interactive[i][j];
			}
			cout << endl;
		}
	}
	else
	{
		cerr << "Error! Please anter another amount for rows." << endl;
		SetTips12();
	}
}

void Tips::SetTips13()
{
	cout << "How many rows? " << endl;
	cin >> rows;
	if (rows > 0)
	{
		//rows_interactive = new char[rows];

		std::vector< std::vector<char> > rows_interactive( rows, std::vector<char>( 12 ) );
		for(int i = 0; i < rows; i++)
		{
			cout << "Row " << i+1 << ": " << endl;
			for (int j = 0; j < 13; j++)
			{
				cout << j+1 << ": ";
				cin >> rows_interactive[i][j];
			}
			cout << endl;
		}
	}
	else
	{
		cerr << "Error! Please anter another amount for rows." << endl;
		SetTips13();
	}

	//CheckTips(sys_type);

}

void Tips::CheckTips(short system_type)
{
	corr_array = new int[100];

	for (int i = 0; i < 99; i++)
	{
		corr_array[i] = 0;
	}

	for (i = 0; i < rows; i++)
	{
		for (int j = 0; j < system_type; j++)
		{
			if (rows_interactive[i][j] == match_active_results[j])
			{
				corr_array[i]++;
			}
		}
	}
}

void main()
{
	Tips New;

	New.FindTipsSystem();
	New.CheckTips(/*New.GetSystem()*/12);
}
  

Share this post


Link to post
Share on other sites
Advertisement
you expect me to read all that without telling me what the error is? no wonder there are no replies to this post.

Share this post


Link to post
Share on other sites
void Tips::CheckTips(short system_type)
{
corr_array = new int[100];

for (int i = 0; i < 99; i++) << should be < 100
{
corr_array = 0;
}



actually... looking at it some more... you make a new array int[100] but you don't delete it anywhere. it's always the same size so you might as well have it as a member.

still don't know what the error is though

[edited by - petewood on November 2, 2002 4:59:09 AM]

Share this post


Link to post
Share on other sites
okay, now i''ve looked at it.

what is the reason for defining the member rows_interactive to be a char** and then later creating a local variable rows_interactive to be a vector of vectors?

Share this post


Link to post
Share on other sites
I have found the error but I dont know what to do, the error is in this code:


  

void Tips::CheckTips(short system_type)
{
corr_array = new int[10];

for (int i = 0; i < 10; i++)
{
corr_array[i] = 0;
}

for (i = 0; i < rows; i++)
{
for (int j = 0; j < system_type; j++)
{
if (rows_interactive[i][j] == match_active_results[j]) // <--- here is the problem

{
corr_array[i] += 1;
}
}
}
}


If you take a look at the if statement, and remove "rows_interactive[j]" with something else, for example like this: if (''1'' == match_active_results[j]), then I get no errors, so...what is the problem? I know that it is something with rows_interactive[i][j]. What return value do I get from rows_interactive[i][j]?

Share this post


Link to post
Share on other sites
rows_interactive doesn''t exist!

as i pointed out above - you need to declare it a vector vector not a char**

Share this post


Link to post
Share on other sites
	char** rows_interactive;


void Tips::SetTips12()
{
cout << "How many rows? " << endl;
cin >> rows;
if (rows > 0)
{
//rows_interactive = new char*[rows];
//rows_interactive = new char[12];
std::vector< std::vector > rows_interactive( rows, std::vector( 12 ) );


this is your problem

make the first version
vector<vector<char> > rows_interactive  


[edited by - petewood on November 2, 2002 1:50:43 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by petewood
you expect me to read all that without telling me what the error is?

quote:
Original post by petewood
actually... looking at it some more... 

quote:
Original post by petewood
okay, now i''ve looked at it.

LOL, had a surprisingly boring evening?-)

Share this post


Link to post
Share on other sites
OK! done...
But I still got the error, how do I acces rows_interactive[j] in vector mode?

Share this post


Link to post
Share on other sites
okay

the line above:

std::vector< std::vector > rows_interactive( rows, std::vector( 12 ) );

should be:

rows_interactive.resize( rows, std::vector( 12 ) );


this is because the vector of vectors already exists (it''s a member of the class). you just need to set it''s size and the default value.

then the rest should work okay.

Share this post


Link to post
Share on other sites
quote:
LOL, had a surprisingly boring evening?-)


(c:

[edited by - petewood on November 3, 2002 1:40:47 PM]

Share this post


Link to post
Share on other sites

  • Advertisement