473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logical error/ whole program contained within.

Can anyone run this program through their compiler or if they can see
a logical error please point it out. I have my tutor working on it at
the moment but I would rather a less ambigious response than the one I
think he will provide.

The test data, A:\\"514650.txt ", appears at the end of the program.
The problem is that the program won't read this file and the debugger
as far as i know how to work it won't point out the mistake of any.
Can anyone also give me a step by step guide to running the debugger
also. I know that you have to put a point in main and then step
through it, but how do I get the debugger to tell me if there is a
possible error within main.
Thank you in advance.

Can anyone tell me the syntax for tellg also. Thank you.
The program:

#include<iostre am.h>
#include<iomani p.h>
#include<fstrea m.h>
#include<string .h>
#include<stdlib .h>
#include<ctype. h>
const char filename1[] = "A:\\514650TD.t xt";
const char filename2[] = "514650VD.D AT";

const int max = 104;
char alphabet[27] = "abcdefghijklmn opqrstuvwxyz";
char numbers[10] = "123456789" ;
char semicolon[5] = ";;;;";
int max_len = 16;
char space[18] = " ";
char i;
char c;
char r;
char d;
char temp_customer_c ode[5];
char temp_balance[5];
char temp_credit_lim it[5];
char temp_partnum[5];
char temp_issue[5];
char temp_customer_c ode1[5];
char temp_customer_c ode2[5];
char value;
char vowels[6];

struct file1 {
char record_type;
char customer_name[20];
long customer_code[5];
char customer_addres s[60];
long customer_balanc e[9];
long credit_limit[7];
}c_record;

struct file2 {
char record_type;
long customer_code[5];
long part_num[6];
long issue_rec[4];
};

struct file3 {
char record_type;
long customer_code[5];
};

struct sum {
int calculation[5];
int calc[6];
int weight_factor[5];
};

int verify(struct file1, int abacus);//function prototype
char temp1[104], *temp_ptr = temp1;

struct file1 rec;
struct file2 rec1;
struct file3 rec2;
struct sum check;

int result;
int remainder;
int mod = 11;
int check_digit;
int count;
int reclen = 103;
int rec1len = 16;
int rec2len = 7;

bool
ok = true;
bool
error = false;
int main()
{
fstream infile;
fstream outfile;
fstream prnfile;

int index;
int count;
int passes = 200;
char *temp_ptr = new char[max];
rec.record_type = c;
rec.record_type = toupper(rec.rec ord_type);

rec1.record_typ e = i;
rec1.record_typ e = toupper(rec1.re cord_type);
rec1.record_typ e = r;
rec1.record_typ e = toupper(rec1.re cord_type);

rec2.record_typ e = d;
rec2.record_typ e = toupper(rec2.re cord_type);

alphabet[27] = toupper(alphabe t[27]);
vowels[6] = toupper(vowels[6]);

union records {
struct file1 rec;
struct file2 rec1;
struct file3 rec2;
struct sum check;
};

union records files;
union records *str_ptr =&files;

infile.open("A: \\514650TD.txt" , ios::in);
if(infile.fail( ))
{
cout<<"The file does not already exist";
exit(1);
}
else
{
cout<<"514650TD is open";
};
outfile.open(fi lename2, ios::out || ios::binary);
if(!outfile.is_ open())
{
cout<<" The file could not be opened "<<endl;;
exit(1);
}
else
{
cout<<" 514650VD is open "<<endl;
};

prnfile.open("l pt1", ios::out || ios::binary);
if(!prnfile.is_ open())
{
cout<< "File could not be opened";
exit(1);
};

prnfile << cout<< "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;
while(infile.pe ek() != EOF)
{
if(temp1[1] == rec.record_type )
{
reclen = strlen(temp1);

cout<< "c record is"
<< strlen(temp1) <<endl;

if(reclen <=103)
{
prnfile<< "Invalid c record does not contain enough characters"
<<temp1[104]<< endl;
};

};
if(temp1[1] == rec1.record_typ e)
{
rec1len = strlen(temp1);

cout<< "i record is"
<< strlen(temp1) <<endl;

if(rec1len <=16)
{
prnfile<< "Invalid i record does not contain enough characters"
<<temp1[104]<< endl;
};

};
if(temp1[1] == rec1.record_typ e)
{
rec1len = strlen(temp1);

cout<< "r record is"
<< strlen(temp1) <<endl;

if(rec1len <=16)
{
prnfile<< "Invalid r record does not contain enough characters"
<<temp1[104]<< endl;
};

};
if(temp1[1] == rec2.record_typ e)
{
rec2len = strlen(temp1);

cout<< "d record is"
<< strlen(temp1) << endl;

if(rec2len <=7)
{
prnfile<< "Invalid d record does not contain enough characters"
<<temp1[104]<< endl;
};
};

strncpy (files.rec.cust omer_name, &temp1[27], 20);
files.rec.custo mer_name[20] = '\0';
strncpy (temp_customer_ code, &temp1[2], 5);
files.rec.custo mer_code[5] = '\0';
files.rec.custo mer_code[5] = atol(temp_custo mer_code);
strncpy (files.rec.cust omer_address, &temp1[27], 60);
files.rec.custo mer_address[60] = '\0';
strncpy (temp_balance, &temp1[87], 9);
files.rec.custo mer_balance[9] = '\0';
strncpy (temp_credit_li mit, &temp1[96], 7);
files.rec.credi t_limit[7] = '\0';
files.rec.credi t_limit[7] = atol(temp_credi t_limit);

strncpy(temp_cu stomer_code1, &temp1[2], 5);
files.rec1.cust omer_code[5] = '\0';
files.rec1.cust omer_code[5] = atol(temp_custo mer_code1);
strncpy(temp_pa rtnum, &temp1[7], 6);
files.rec1.part _num[6] = '\0';
files.rec1.part _num[6] = atol(temp_partn um);
strncpy(temp_is sue, &temp1[13], 4);
files.rec1.issu e_rec[4] = '\0';
files.rec1.issu e_rec[4] = atol(temp_issue );

strncpy(temp_cu stomer_code2, &temp1[2], 5);
files.rec2.cust omer_code[5] = '\0';
files.rec2.cust omer_code[5] = atol(temp_custo mer_code2);

if(temp1[1] != files.rec.recor d_type || files.rec1.reco rd_type ||
files.rec2.reco rd_type)
{
ok = false;
error = true;
prnfile << "Error files";
prnfile << temp1[104] <<endl;
}
else
if(temp1[1] == files.rec.recor d_type || files.rec1.reco rd_type ||
files.rec2.reco rd_type)
{
ok = true;
error = false;
cout<< "valid record type" <<endl;
outfile.write(( &value), sizeof(files.re c.record_type)) ;
outfile.write(( &value), sizeof(files.re c1.record_type) );
outfile.write(( &value), sizeof(files.re c2.record_type) );
};
count = 0;
temp_ptr = temp1;
cin.getline(tem p_ptr, max);
if(temp1[2] = numbers[10])
{
do{

for(index = 0; index < temp1[6]; index++)
rec.customer_co de[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec.cu stomer_code[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater" << endl;
};
check.calculati on[5] =
(sizeof(check.c alculation)/sizeof(check.ca lculation[0]));

for(count = 0; count < 5; count++)
{
check.calculati on[1] = check.weight_fa ctor[1] * rec.customer_co de[1];
check.calculati on[2] = check.weight_fa ctor[2] * rec.customer_co de[2];
check.calculati on[3] = check.weight_fa ctor[3] * rec.customer_co de[3];
check.calculati on[4] = check.weight_fa ctor[4] * rec.customer_co de[4];
check.calculati on[5] = check.weight_fa ctor[5] * rec.customer_co de[5];
};

result = (sizeof(result)/sizeof(check.ca lculation[0]));

while(count++)
{
result = check.calculati on[1] + check.calculati on[2] +
check.calculati on[3] + check.calculati on[4] + check.calculati on[5];
};

remainder = result % mod;

check_digit = mod - remainder;

if(check_digit + remainder == mod)
{
ok = true;
error = false;
}
else
{
ok = false;
error = true;
};
if(ok = true)
{
outfile.write(( &value), sizeof(files.re c.customer_code ));
};

//count must be correct from its state in the infinite loop.
if(temp1[7] = alphabet[24])
{
count = 0;
do{
for(index = 0; index < temp1[27]; index++)
rec.customer_na me[20] = temp1[index];
}
while(count < passes);
count++;
}
else
{
prnfile<< "Invalid customer name, is not in an aphabetical format"
<< temp1[104] << endl;
};

if(temp1[1] == files.rec.recor d_type && temp1[27] == alphabet[24])
{
count = 0;
do{

for(index = 0; index < temp1[86]; index++);
rec.customer_ad dress[60] = temp1[index];
int verify(struct file1, int abacus);
count++;
}
while(count < passes);

}
else
if(files.rec.cu stomer_address[60] != alphabet[24] &&
files.rec.custo mer_address[60] != numbers[10])
{
if(files.rec.cu stomer_address[60] > space[18] ||
files.rec.custo mer_address[60] != semicolon[5])
{
prnfile<< "Invalid customer address"
<< "incorrect address format"
<<temp1[104] <<endl;
};
};

if(temp1[1] == files.rec.recor d_type && temp1[87] == numbers[10])
{
count = 0;
do{
for(index =0; index < temp1[95]; index++)
files.rec.custo mer_balance[9] = temp1[index];
count++;
}
while(count < passes);

}
else
if(files.rec.cu stomer_balance[9] != numbers[10])
{
ok = false;
error = true;
prnfile<<"Inval id customer balance, does not contain numerical
format"
<<temp1[104] <<endl;
};
if(files.rec.cu stomer_balance[9] = numbers[10])
{
ok = true;
error = false;
outfile.write(( &value), sizeof(files.re c.customer_bala nce));
};

if(temp1[1] == files.rec.recor d_type && temp1[96] == numbers[10])
{
count = 0;
do{
for(index =0; index < temp1[102]; index++)
files.rec.credi t_limit[7] = temp1[index];

}
while(count < passes);
count++;
}
else
if(files.rec.cr edit_limit[7] != numbers[10])
{
cout<<"Invalid credit limit, does not contain numerical
format"<<endl;
};
if(files.rec.cr edit_limit[7] = numbers[10])
{
ok = true;
error = false;
outfile.write(( &value), sizeof(files.re c.credit_limit) );
};
if(temp1[1] = files.rec1.reco rd_type)// needs check digit 11
formulae.
{
do{
count = 0;

for(index = 1; index < temp1[6]; index++);
files.rec1.cust omer_code[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec1.c ustomer_code[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater"
<<temp1[16]<< endl;
};
if(files.rec1.c ustomer_code[5] = numbers[10])
{
ok = true;
error = false;
outfile.write(( &value), sizeof(files.re c1.customer_cod e));
};

if(temp1[1] = files.rec1.reco rd_type)//need check digit 11 formulae.
{
do{
for(index =7; index < temp1[12]; index++)
files.rec1.part _num[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec1.p art_num[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater"
<<temp1[16]<< endl;
};
if(files.rec1.p art_num[5] = numbers[10])
{
ok = true;
error = false;
outfile.write(( &value), sizeof(files.re c1.part_num));
};

// if check digit ok then do.
check.calculati on[5] =
(sizeof(check.c alculation)/sizeof(check.ca lculation[0]));

for(count = 0; count < 5; count++)
{
check.calculati on[1] = check.weight_fa ctor[1] *
files.rec1.cust omer_code[1];
check.calculati on[2] = check.weight_fa ctor[2] *
files.rec1.cust omer_code[2];
check.calculati on[3] = check.weight_fa ctor[3] *
files.rec1.cust omer_code[3];
check.calculati on[4] = check.weight_fa ctor[4] *
files.rec1.cust omer_code[4];
check.calculati on[5] = check.weight_fa ctor[5] *
files.rec1.cust omer_code[5];
};

result = (sizeof(result)/sizeof(check.ca lculation[0]));

while(count++)
{
result = check.calculati on[1] + check.calculati on[2] +
check.calculati on[3] + check.calculati on[4] + check.calculati on[5];
};

remainder = result % mod;

check_digit = mod - remainder;

if(check_digit + remainder == mod)
{
ok = true;
error = false;
}
else
{
ok = false;
error = true;
};
if(ok = true)
{
outfile.write(( &value), sizeof(files.re c1.customer_cod e));
};
check.calculati on[5] =
(sizeof(check.c alculation)/sizeof(check.ca lculation[0]));

for(count = 0; count < 5; count++)
{
check.calculati on[1] = check.weight_fa ctor[1] *
files.rec1.part _num[1];
check.calculati on[2] = check.weight_fa ctor[2] *
files.rec1.part _num[2];
check.calculati on[3] = check.weight_fa ctor[3] *
files.rec1.part _num[3];
check.calculati on[4] = check.weight_fa ctor[4] *
files.rec1.part _num[4];
check.calculati on[5] = check.weight_fa ctor[5] *
files.rec1.part _num[5];
check.calculati on[6] = check.weight_fa ctor[6] *
files.rec1.part _num[6];
};

result = (sizeof(result)/sizeof(check.ca lculation[0]));

while(count++)
{
result = check.calculati on[1] + check.calculati on[2] +
check.calculati on[3] + check.calculati on[4] + check.calculati on[5];
};

remainder = result % mod;

check_digit = mod - remainder;

if(check_digit + remainder == mod)
{
ok = true;
error = false;
}
else
{
ok = false;
error = true;
};
if(ok = true)
{
outfile.write(( &value), sizeof(files.re c1.part_num));
};///////////////////////////

if(temp1[1] = files.rec2.reco rd_type)
{
if(temp1[2] = numbers[10])
{
do{

for(index = 0; index < temp1[6]; index++)
files.rec2.cust omer_code[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec2.c ustomer_code[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater" << endl;
};

};


};
infile.close();
outfile.close() ;
prnfile.close() ;
return 0;
};

int verify(struct file1, int abacus, char semi_colons[2] = ";")
{
fstream prnfile;
fstream infile;
fstream outfile;
int vowel_check = 0;
int word = 0;
const int max_word = 16;
const int vowel_average = 2;
if(rec.customer _address[60] = vowels[6])
{
do{

for(temp_ptr[max]; &rec.customer_a ddress[1];);
for(temp_ptr[max] = rec.customer_ad dress[1]; temp_ptr++;);
temp_ptr = '\0';
if(temp_ptr[max] = semi_colons[2])
{
word++;
};
for(temp_ptr++; abacus++;);
if(word >=1)
{
cout<<"word length is"<< abacus <<endl;
if(abacus > max_word)
{
prnfile<< "CUSTOMER ADDRESS ERRORS"
<< "Word is invalid. Entry contains too many characters"
<< temp1[104] <<endl;
}
else
if(abacus <= max_word)
{
cout<< "First check completed for customer address"<< endl;
};
};
if(temp_ptr[max] = vowels[6])
{
vowel_check++;
}
else
if(temp_ptr[max] != vowels[6])
{
prnfile<< "CUSTOMER ADDRESS ERRORS"
<< "Invalid customer address"
<< temp1[104] << endl;
};
if(vowel_check >= vowel_average)
{
ok = true;
error = false;
outfile.write(( &value), sizeof(rec.cust omer_address));
};
}
while(infile.eo f());

};
return ok;c 98581 tod terry
312;Dawlish;Dri ve;Ilford;Essex ;IG3;9ED; 000000.25
00000.100
c 45238 kelvin patrick
21;castleton;dr ive;Ilford;Esse x;IG3;2DQ; 00000.076 0000.1600
i 23759 856343 9685
d 54789
d 35498
i 49586 412562 3759
c 26424 sean o'connor 567;ley;street; leytonstone;Ess ex;W15;
000000.24 0000.2000
};
The test data:
Jul 19 '05 #1
4 4002
muser wrote:
Can anyone run this program through their compiler or if they can see
a logical error please point it out. I have my tutor working on it at
the moment but I would rather a less ambigious response than the one I
think he will provide.


Well, I see at least one glaring logic error in your code. In many of
your if() statements, you are incorrectly performing assignment operations

a = b

when you *should* be performing value comparison operations

a == b

e.g.,

if ( a = b ) // WRONG -- this assigns b's value into a

if ( a == b ) // CORRECT -- this compares the values in a and b

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link58 09{at}now.here. com
Jul 19 '05 #2
Scads of errors, suggest you get practising with the debugger. But I'll
point out a few below.

This is the first newbie lesson, a compiling program is not a debugged
program, nothing like.

"muser" <ch**********@h otmail.com> wrote in message
news:f9******** *************** ***@posting.goo gle.com...
Can anyone run this program through their compiler or if they can see
a logical error please point it out. I have my tutor working on it at
the moment but I would rather a less ambigious response than the one I
think he will provide.

The test data, A:\\"514650.txt ", appears at the end of the program.
The problem is that the program won't read this file and the debugger
as far as i know how to work it won't point out the mistake of any.
Can anyone also give me a step by step guide to running the debugger
also. I know that you have to put a point in main and then step
through it, but how do I get the debugger to tell me if there is a
possible error within main.
Thank you in advance.

Can anyone tell me the syntax for tellg also. Thank you.
The program:

#include<iostre am.h>
#include<iomani p.h>
#include<fstrea m.h>
#include<string .h>
#include<stdlib .h>
#include<ctype. h>
const char filename1[] = "A:\\514650TD.t xt";
const char filename2[] = "514650VD.D AT";

const int max = 104;
char alphabet[27] = "abcdefghijklmn opqrstuvwxyz";
char numbers[10] = "123456789" ;
char semicolon[5] = ";;;;";
int max_len = 16;
char space[18] = " ";
char i;
char c;
char r;
char d;

These above are all uninitialised varaibles (or rather zero initialised)
which is fine but ...
char temp_customer_c ode[5];
char temp_balance[5];
char temp_credit_lim it[5];
char temp_partnum[5];
char temp_issue[5];
char temp_customer_c ode1[5];
char temp_customer_c ode2[5];
char value;
char vowels[6];

struct file1 {
char record_type;
char customer_name[20];
long customer_code[5];
This is wrong. That is five longs! You just want one

long customer_code;
char customer_addres s[60];
long customer_balanc e[9];
Diito

long customer_balanc e;
long credit_limit[7];
Ditto

long credit_limit;
}c_record;

struct file2 {
char record_type;
long customer_code[5];
long part_num[6];
long issue_rec[4];
Ditto, ditto, ditto.
};

struct file3 {
char record_type;
long customer_code[5];
Ditto.
};

struct sum {
int calculation[5];
int calc[6];
int weight_factor[5];
};

int verify(struct file1, int abacus);//function prototype
char temp1[104], *temp_ptr = temp1;

struct file1 rec;
struct file2 rec1;
struct file3 rec2;
struct sum check;

int result;
int remainder;
int mod = 11;
int check_digit;
int count;
int reclen = 103;
int rec1len = 16;
int rec2len = 7;

bool
ok = true;
bool
error = false;
int main()
{
fstream infile;
fstream outfile;
fstream prnfile;

int index;
int count;
int passes = 200;
char *temp_ptr = new char[max];
rec.record_type = c;
rec.record_type = toupper(rec.rec ord_type);

Here you are using the uninitalised variable above. I suspect that what you
really meant to say was

rec.record_type = 'C';

No need for the variable or for the toupper.

rec1.record_typ e = i;
rec1.record_typ e = toupper(rec1.re cord_type);
rec1.record_typ e = r;
rec1.record_typ e = toupper(rec1.re cord_type);

Ditto, and why assign i and then immediately change it to r?
rec2.record_typ e = d;
rec2.record_typ e = toupper(rec2.re cord_type);
Ditto.

alphabet[27] = toupper(alphabe t[27]);
vowels[6] = toupper(vowels[6]);
Neither of these do what you think they do. toupper converts a *single*
character to uppercase. Also alphabet[27] and vowels[6] do not exist because
the arrays are too small. Obviously what you want to do is convert the
entrie array to upper case, but if you want that why not declare it that way
in the first place?


union records {
struct file1 rec;
struct file2 rec1;
struct file3 rec2;
struct sum check;
};

union records files;
union records *str_ptr =&files;

infile.open("A: \\514650TD.txt" , ios::in);
if(infile.fail( ))
{
cout<<"The file does not already exist";
exit(1);
}
else
{
cout<<"514650TD is open";
};
outfile.open(fi lename2, ios::out || ios::binary);
if(!outfile.is_ open())
{
cout<<" The file could not be opened "<<endl;;
exit(1);
}
else
{
cout<<" 514650VD is open "<<endl;
};

prnfile.open("l pt1", ios::out || ios::binary);
if(!prnfile.is_ open())
{
cout<< "File could not be opened";
exit(1);
};

prnfile << cout<< "C_RECORD, I-R RECORD, D_RECORD ERRORS" << endl;
while(infile.pe ek() != EOF)
{
if(temp1[1] == rec.record_type )
{
reclen = strlen(temp1);
temp1 is also completely uninitalised, not sure what you are trying to
acheive here, perhaps you missed out a read statement?

cout<< "c record is"
<< strlen(temp1) <<endl;

if(reclen <=103)
{
prnfile<< "Invalid c record does not contain enough characters"
<<temp1[104]<< endl;
Again this is the same mistake you made with alphabet and vowels. temp1[104]
is a *single* character, not the entire string. The way to output the entire
string is

<< temp1 << endl;
};

};
if(temp1[1] == rec1.record_typ e)
{
rec1len = strlen(temp1);

cout<< "i record is"
<< strlen(temp1) <<endl;

if(rec1len <=16)
{
prnfile<< "Invalid i record does not contain enough characters"
<<temp1[104]<< endl;
Ditto
};

};
if(temp1[1] == rec1.record_typ e)
Two comparisons to rec1.record_typ e, something mysterious going on here.
Perhaps you need rec, rec1, rec2, and rec3. Seems you are short of one
record type.
{
rec1len = strlen(temp1);

cout<< "r record is"
<< strlen(temp1) <<endl;

if(rec1len <=16)
{
prnfile<< "Invalid r record does not contain enough characters"
<<temp1[104]<< endl;
Ditto.
};

};
if(temp1[1] == rec2.record_typ e)
{
rec2len = strlen(temp1);

cout<< "d record is"
<< strlen(temp1) << endl;

if(rec2len <=7)
{
prnfile<< "Invalid d record does not contain enough characters"
<<temp1[104]<< endl;
Ditto.
};
};

strncpy (files.rec.cust omer_name, &temp1[27], 20);
files.rec.custo mer_name[20] = '\0';
strncpy (temp_customer_ code, &temp1[2], 5);
files.rec.custo mer_code[5] = '\0';
files.rec.custo mer_code[5] = atol(temp_custo mer_code);
With the correction to file1 above

files.rec.custo mer_code = atol(temp_custo mer_code);
strncpy (files.rec.cust omer_address, &temp1[27], 60);
files.rec.custo mer_address[60] = '\0';
strncpy (temp_balance, &temp1[87], 9);
files.rec.custo mer_balance[9] = '\0';
strncpy (temp_credit_li mit, &temp1[96], 7);
files.rec.credi t_limit[7] = '\0';
files.rec.credi t_limit[7] = atol(temp_credi t_limit);
Ditto

files.rec.credi t_limit = atol(temp_credi t_limit);

strncpy(temp_cu stomer_code1, &temp1[2], 5);
files.rec1.cust omer_code[5] = '\0';
files.rec1.cust omer_code[5] = atol(temp_custo mer_code1);


Ditto

files.rec1.cust omer_code = atol(temp_custo mer_code1);

[snip]

I'm sure there are many many more errors. I just found the above by
eyeballing the code, I try to work out what it is actually supposed to do.

john
Jul 19 '05 #3
Sin
> Can anyone also give me a step by step guide to running the debugger
also. I know that you have to put a point in main and then step
through it, but how do I get the debugger to tell me if there is a
possible error within main.


A debugger doens't tell you where the bugs are... It allows you to see what
code is being executed when, and what it does to the data used by it...

There are several ways to use the debugger. Sometimes you'll have an idea of
where the program fails and you can put a breakpoint before or on that spot.
You then execute the program and it will stop at that breakpoint. You can
then inspect the data to make sure it's in a valid (or expected) state, and
then step one function at a time to see if they do as expected.

As someone mentionned, you are using the assignation (=) operator rather
than the comparison operator (==). Had you used the debugger, you would have
seen that sometimes this statement would not work as expected. If both A and
B are zero for example, the debugger would have skipped the inner if rather
than (what YOU would have expected) enter in it...

Other ways to use the debugger would be to step through all the code, not
using breakpoints. Some debuggers will also allow to install evential
breakpoints (ex: "break when A changes") which can be usefull in special
occasions.

There's another kind of debugger than goes further, they are called
profilers. These might for example watch memory allocation/deallocation for
you, memory overruns, etc. They might also tell you which code has been used
within an execution to allow you to do a full coverage of the
functionnalitie s of your program.

Like all things, experience is the key...

Alex.
Jul 19 '05 #4
Jim Fischer wrote:
muser wrote:
Can anyone run this program through their compiler or if they can see
a logical error please point it out. I have my tutor working on it at
the moment but I would rather a less ambigious response than the one I
think he will provide.

Well, I see at least one glaring logic error in your code. In many of
your if() statements, you are incorrectly performing assignment operations

a = b

when you *should* be performing value comparison operations

a == b

e.g.,

if ( a = b ) // WRONG -- this assigns b's value into a

if ( a == b ) // CORRECT -- this compares the values in a and b


BTW, if your compiler emits warning messages as it translates your C/C++
program, DO NOT ignore those warnings. Warning messages identify
problems that are very real -- e.g., common logic errors that make a
program behave in unexpected / undesirable ways at run time. So DO NOT
get yourself into the mindset that you can safely ignore all warning
messages. This is folly!

BTW2, if the compiler (and/or linker) does not emit any warning/error
messages, this DOES NOT mean the program is "correct". There may still
be logic errors in your code that cause unexpected / undesirable
behaviors at run time. (This is when the debugger software comes in
handy...)

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link58 09{at}now.here. com
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

67
4196
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++....
9
2502
by: torbs | last post by:
Hi I am creating a page for stretchfilm. In this page you can chose between a short medium and long version of the film at any point in the film. It is in norwegian, but just press play. URL: http://www.media.uio.no/sherlockholmes/main.php?plugin=quicktime&hastighet=lav
4
1632
by: GRoll21 | last post by:
The problem starts during my while loop. It checks to see if they hit x or X. If they did, then that means the user wants to exit. Then should go on and hit the return statement. It just quits. When I hit x, it pauses for a second then just goes to the next line on the cmd prompt. My other returns work just fine though. I'm sure its just a...
6
4721
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
0
3548
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
9
3732
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
0
2041
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the increment operator in a class and then defining a derived class and using the derived class. When I try to use the increment operator on an instance of...
11
4252
by: Bryan Crouse | last post by:
I am looking a way to do error checking on a string at compile time, and if the string isn't the correct length have then have the compiler throw an error. I am working an embedded software that will require individual builds for each device so that the device serial number is contained in the program memory. To do this, the C application...
3
8742
blazedaces
by: blazedaces | last post by:
Hello, it's been a while since I posted on these forums. My issue I think isn't as much in my code as it's in the syntax and structure in references other packages. I'll get straight to it then: There's a package called "randomX" which, while I don't know if you care to know, has a program that accesses a site called hotbits to produce true...
0
7542
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7467
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7500
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5110
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.