By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,028 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,028 IT Pros & Developers. It's quick & easy.

Logical error/ whole program contained within.

P: n/a
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<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
const char filename1[] = "A:\\514650TD.txt";
const char filename2[] = "514650VD.DAT";

const int max = 104;
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";
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_code[5];
char temp_balance[5];
char temp_credit_limit[5];
char temp_partnum[5];
char temp_issue[5];
char temp_customer_code1[5];
char temp_customer_code2[5];
char value;
char vowels[6];

struct file1 {
char record_type;
char customer_name[20];
long customer_code[5];
char customer_address[60];
long customer_balance[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.record_type);

rec1.record_type = i;
rec1.record_type = toupper(rec1.record_type);
rec1.record_type = r;
rec1.record_type = toupper(rec1.record_type);

rec2.record_type = d;
rec2.record_type = toupper(rec2.record_type);

alphabet[27] = toupper(alphabet[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(filename2, 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("lpt1", 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.peek() != 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_type)
{
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_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;
};

};
if(temp1[1] == rec2.record_type)
{
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.customer_name, &temp1[27], 20);
files.rec.customer_name[20] = '\0';
strncpy (temp_customer_code, &temp1[2], 5);
files.rec.customer_code[5] = '\0';
files.rec.customer_code[5] = atol(temp_customer_code);
strncpy (files.rec.customer_address, &temp1[27], 60);
files.rec.customer_address[60] = '\0';
strncpy (temp_balance, &temp1[87], 9);
files.rec.customer_balance[9] = '\0';
strncpy (temp_credit_limit, &temp1[96], 7);
files.rec.credit_limit[7] = '\0';
files.rec.credit_limit[7] = atol(temp_credit_limit);

strncpy(temp_customer_code1, &temp1[2], 5);
files.rec1.customer_code[5] = '\0';
files.rec1.customer_code[5] = atol(temp_customer_code1);
strncpy(temp_partnum, &temp1[7], 6);
files.rec1.part_num[6] = '\0';
files.rec1.part_num[6] = atol(temp_partnum);
strncpy(temp_issue, &temp1[13], 4);
files.rec1.issue_rec[4] = '\0';
files.rec1.issue_rec[4] = atol(temp_issue);

strncpy(temp_customer_code2, &temp1[2], 5);
files.rec2.customer_code[5] = '\0';
files.rec2.customer_code[5] = atol(temp_customer_code2);

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

for(index = 0; index < temp1[6]; index++)
rec.customer_code[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec.customer_code[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater" << endl;
};
check.calculation[5] =
(sizeof(check.calculation)/sizeof(check.calculation[0]));

for(count = 0; count < 5; count++)
{
check.calculation[1] = check.weight_factor[1] * rec.customer_code[1];
check.calculation[2] = check.weight_factor[2] * rec.customer_code[2];
check.calculation[3] = check.weight_factor[3] * rec.customer_code[3];
check.calculation[4] = check.weight_factor[4] * rec.customer_code[4];
check.calculation[5] = check.weight_factor[5] * rec.customer_code[5];
};

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

while(count++)
{
result = check.calculation[1] + check.calculation[2] +
check.calculation[3] + check.calculation[4] + check.calculation[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.rec.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_name[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.record_type && temp1[27] == alphabet[24])
{
count = 0;
do{

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

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

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

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

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

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

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

if(temp1[1] = files.rec1.record_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.part_num[5] != numbers[10])
{
prnfile<< "customer code invalid code, code contains a non digit
charater"
<<temp1[16]<< endl;
};
if(files.rec1.part_num[5] = numbers[10])
{
ok = true;
error = false;
outfile.write((&value), sizeof(files.rec1.part_num));
};

// if check digit ok then do.
check.calculation[5] =
(sizeof(check.calculation)/sizeof(check.calculation[0]));

for(count = 0; count < 5; count++)
{
check.calculation[1] = check.weight_factor[1] *
files.rec1.customer_code[1];
check.calculation[2] = check.weight_factor[2] *
files.rec1.customer_code[2];
check.calculation[3] = check.weight_factor[3] *
files.rec1.customer_code[3];
check.calculation[4] = check.weight_factor[4] *
files.rec1.customer_code[4];
check.calculation[5] = check.weight_factor[5] *
files.rec1.customer_code[5];
};

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

while(count++)
{
result = check.calculation[1] + check.calculation[2] +
check.calculation[3] + check.calculation[4] + check.calculation[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.rec1.customer_code));
};
check.calculation[5] =
(sizeof(check.calculation)/sizeof(check.calculation[0]));

for(count = 0; count < 5; count++)
{
check.calculation[1] = check.weight_factor[1] *
files.rec1.part_num[1];
check.calculation[2] = check.weight_factor[2] *
files.rec1.part_num[2];
check.calculation[3] = check.weight_factor[3] *
files.rec1.part_num[3];
check.calculation[4] = check.weight_factor[4] *
files.rec1.part_num[4];
check.calculation[5] = check.weight_factor[5] *
files.rec1.part_num[5];
check.calculation[6] = check.weight_factor[6] *
files.rec1.part_num[6];
};

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

while(count++)
{
result = check.calculation[1] + check.calculation[2] +
check.calculation[3] + check.calculation[4] + check.calculation[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.rec1.part_num));
};///////////////////////////

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

for(index = 0; index < temp1[6]; index++)
files.rec2.customer_code[5] = temp1[index];
}
while(count < passes);
count++;
}
else
if(files.rec2.customer_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_address[1];);
for(temp_ptr[max] = rec.customer_address[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.customer_address));
};
}
while(infile.eof());

};
return ok;c 98581 tod terry
312;Dawlish;Drive;Ilford;Essex;IG3;9ED; 000000.25
00000.100
c 45238 kelvin patrick
21;castleton;drive;Ilford;Essex;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;Essex;W15;
000000.24 0000.2000
};
The test data:
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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_link5809{at}now.here.com
Jul 19 '05 #2

P: n/a
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**********@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
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<iostream.h>
#include<iomanip.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
const char filename1[] = "A:\\514650TD.txt";
const char filename2[] = "514650VD.DAT";

const int max = 104;
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";
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_code[5];
char temp_balance[5];
char temp_credit_limit[5];
char temp_partnum[5];
char temp_issue[5];
char temp_customer_code1[5];
char temp_customer_code2[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_address[60];
long customer_balance[9];
Diito

long customer_balance;
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.record_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_type = i;
rec1.record_type = toupper(rec1.record_type);
rec1.record_type = r;
rec1.record_type = toupper(rec1.record_type);

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

alphabet[27] = toupper(alphabet[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(filename2, 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("lpt1", 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.peek() != 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_type)
{
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_type)
Two comparisons to rec1.record_type, 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_type)
{
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.customer_name, &temp1[27], 20);
files.rec.customer_name[20] = '\0';
strncpy (temp_customer_code, &temp1[2], 5);
files.rec.customer_code[5] = '\0';
files.rec.customer_code[5] = atol(temp_customer_code);
With the correction to file1 above

files.rec.customer_code = atol(temp_customer_code);
strncpy (files.rec.customer_address, &temp1[27], 60);
files.rec.customer_address[60] = '\0';
strncpy (temp_balance, &temp1[87], 9);
files.rec.customer_balance[9] = '\0';
strncpy (temp_credit_limit, &temp1[96], 7);
files.rec.credit_limit[7] = '\0';
files.rec.credit_limit[7] = atol(temp_credit_limit);
Ditto

files.rec.credit_limit = atol(temp_credit_limit);

strncpy(temp_customer_code1, &temp1[2], 5);
files.rec1.customer_code[5] = '\0';
files.rec1.customer_code[5] = atol(temp_customer_code1);


Ditto

files.rec1.customer_code = atol(temp_customer_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

P: n/a
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
functionnalities of your program.

Like all things, experience is the key...

Alex.
Jul 19 '05 #4

P: n/a
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_link5809{at}now.here.com
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.