function definition problem

M

muser

The following error appears for the code I'm writing:


error C2062: type 'int' unexpected
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2143:
syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2447:
missing function header (old-style formal list?)
Error executing cl.exe.

Zenith.obj - 3 error(s), 0 warning(s)

All errors are related to the function definition, all structures are
global declared and I tried decalring the variable check_digit with no
success.
Those that have responded in the past may already have seen this code
and it would be a pleasure to hear from you again.

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

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


int check_mod(union records, int check_digit);// function prototype.




function defintion.
int check_mod(files, int check_digit)
{

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.rec.customer_code));
};

};
 
R

Roel Schroeven

muser said:
The following error appears for the code I'm writing:


error C2062: type 'int' unexpected
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2143:
syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2447:
missing function header (old-style formal list?)
Error executing cl.exe.

Zenith.obj - 3 error(s), 0 warning(s)

All errors are related to the function definition, all structures are
global declared and I tried decalring the variable check_digit with no
success.
Those that have responded in the past may already have seen this code
and it would be a pleasure to hear from you again.

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

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


int check_mod(union records, int check_digit);// function prototype.




function defintion.
int check_mod(files, int check_digit)

Wouldn't that have to be like the following?

int check_mod(union records files, int check_digit)
 
J

Jakob Bieling

muser said:
The following error appears for the code I'm writing:


error C2062: type 'int' unexpected
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2143:
syntax error : missing ';' before '{'
C:\Program Files\Microsoft Visual
Studio\MyProjects\Valid\Zenith124\Zenith.cpp(427) : error C2447:
missing function header (old-style formal list?)
Error executing cl.exe.

Zenith.obj - 3 error(s), 0 warning(s)

All errors are related to the function definition, all structures are
global declared and I tried decalring the variable check_digit with no
success.
Those that have responded in the past may already have seen this code
and it would be a pleasure to hear from you again.

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

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


int check_mod(union records, int check_digit);// function prototype.




function defintion.
int check_mod(files, int check_digit)

Your prototype does not match the definition. Did you mean:

int check_mod(union records, int check_digit)

?

Other than that, pretty much every line of your code seems flawed. Maybe
you want to look over it again and read out what you are doing with each
line to find out what you /want/ to do and what you are /actually/ doing.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top