Ok heres a program, I won't go into great detail about what it does but the general problem is it is generating an access violation, heres the code:
#include <iostream.h>
#define MAX 500
class dip {
private:
int diparray[MAX];
int people;
int words;
int convar;
int covar;
int recvar;
int startvar;
int dipcount;
int maxcount;
public:
dip (int invar1, int invar2);
void calc (void);
void sort (void);
void output (void);
int complete;
};
dip::dip (int invar1, int invar2)
{
people = invar1;
words = invar2;
dipcount = 1;
complete = 0;
recvar = 0;
maxcount = words - 1;
//Place people into array for functioning
for (covar=1; covar<=people; covar++)
{
diparray[covar] = covar;
}
}
void dip::calc(void)
{
//Find person to start with
recvar++;
while (diparray[recvar]==0)
{
recvar++;
}
recvar=startvar;
recvar=recvar - 1;
for (convar=1; convar<=words; convar++)
{
recvar++;
if (recvar > people)
{
//Reset dip once the last person is reached
recvar = startvar;
}
if (diparray[recvar] == 0) // Debugger marks the error here
{
while (diparray[recvar] == 0)
{
recvar++;
if (recvar > people)
{
recvar = startvar;
}
}
}
}
//Person to remove is known as recvar, unless recvar is last person left check
if (dipcount == maxcount)
{
complete = 1;
}
dipcount++;
}
void dip::sort(void)
{
while (complete != 1)
{
//Make removed person in the control array = 0
diparray[recvar] = 0;
dip::calc();
}
cout << "Person " << recvar << " wins the dip";
cout << "\n\n\nEND OR PROGRAM";
}
void main(void)
{
int x;
int y;
cout<<"Enter Number of People: "; cin>>x;
cout<<"Enter Number of Words in Dip: "; cin>>y;
dip check(x,y);
check.calc();
check.sort();
}
***
Now no errors or warning are displayed upon compile. Anyone know what the problem is, it seems to have something to do with the array diparray. Thanks in advance
Warren Brown
wazzer@btinternet.com
#include <iostream.h>
#define MAX 500
class dip {
private:
int diparray[MAX];
int people;
int words;
int convar;
int covar;
int recvar;
int startvar;
int dipcount;
int maxcount;
public:
dip (int invar1, int invar2);
void calc (void);
void sort (void);
void output (void);
int complete;
};
dip::dip (int invar1, int invar2)
{
people = invar1;
words = invar2;
dipcount = 1;
complete = 0;
recvar = 0;
maxcount = words - 1;
//Place people into array for functioning
for (covar=1; covar<=people; covar++)
{
diparray[covar] = covar;
}
}
void dip::calc(void)
{
//Find person to start with
recvar++;
while (diparray[recvar]==0)
{
recvar++;
}
recvar=startvar;
recvar=recvar - 1;
for (convar=1; convar<=words; convar++)
{
recvar++;
if (recvar > people)
{
//Reset dip once the last person is reached
recvar = startvar;
}
if (diparray[recvar] == 0) // Debugger marks the error here
{
while (diparray[recvar] == 0)
{
recvar++;
if (recvar > people)
{
recvar = startvar;
}
}
}
}
//Person to remove is known as recvar, unless recvar is last person left check
if (dipcount == maxcount)
{
complete = 1;
}
dipcount++;
}
void dip::sort(void)
{
while (complete != 1)
{
//Make removed person in the control array = 0
diparray[recvar] = 0;
dip::calc();
}
cout << "Person " << recvar << " wins the dip";
cout << "\n\n\nEND OR PROGRAM";
}
void main(void)
{
int x;
int y;
cout<<"Enter Number of People: "; cin>>x;
cout<<"Enter Number of Words in Dip: "; cin>>y;
dip check(x,y);
check.calc();
check.sort();
}
***
Now no errors or warning are displayed upon compile. Anyone know what the problem is, it seems to have something to do with the array diparray. Thanks in advance
Warren Brown
wazzer@btinternet.com