Resolving a CPP 6 Syntax Error - Declaration syntax error

  • Context: C/C++ 
  • Thread starter Thread starter ozgurakkas
  • Start date Start date
  • Tags Tags
    Error
Click For Summary

Discussion Overview

The discussion revolves around a syntax error encountered in a C++ program, specifically related to the declaration of the function "int low(int [])". Participants explore potential solutions and issues related to the program's structure and execution.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant reports a "Declaration syntax error" related to "int low(int [])" and seeks assistance.
  • Another participant suggests that the function declaration should be changed from "void main()" to "int main()", indicating this might resolve the issue.
  • A later reply confirms that changing "void main()" to "int main()" resolves the compilation issue on a different computer.
  • One participant mentions that they did not encounter any syntax errors in the function "int low(int [])" despite the reported issues.
  • Another participant notes that after changing to "int main()", the program compiles successfully but experiences an issue where the compiler shuts off unexpectedly when running the program.

Areas of Agreement / Disagreement

There is no consensus on the root cause of the original syntax error, as participants have differing experiences with the program. Some agree that changing "void main()" to "int main()" resolves issues, while others report different behaviors when running the program.

Contextual Notes

Participants express varying experiences with the program's execution, including differences in behavior on different computers and the handling of the main function declaration. The discussion does not resolve the underlying reasons for the discrepancies.

Who May Find This Useful

Individuals interested in C++ programming, particularly those encountering similar syntax errors or issues with function declarations and program execution.

ozgurakkas
Messages
14
Reaction score
0
I have made this program, and everything seems to be fine, except one error which says
"Declaration syntax error" in CPP 6, which is "int low (int [])" I keep getting the same error. Anyone can help me with this?





#include <stdio.h>
#define NUM 5
void fillarray( int []);
double mean1(int []);
int high(int []);
int low(int []);
void main()
{
int scores [NUM];
fillarray (scores);
printf("The class average is %1.2f\n", mean1(scores));
printf("The highest score is %d\n", high(scores));
printf("The lowest score is %d\n", low(scores));
}
void fillarray (int scores [])
{
int x;
for (x=0;x<NUM;x++)
{
printf("Enter the score number %d\n", x+1);
scanf("%d", &scores[x]);
}
}
double mean1(int scores[])
{
int x, sum=0;
double m;
for (x=0;x<NUM;x++)
sum=sum + scores[x];
m=(double)sum/NUM;
return m;
}
int high(int scores[])
{
int x, h= scores[0];
for (x=1;x<NUM;x++)
if (h<scores[x])
h=scores[x];
return h;
}
int low(int scores[])
{
int x, l=scores [0];
for (x=l;x<NUM;x++)
if (l>scores[x])
l= scores[x];
return l;
}
 
Technology news on Phys.org
ozgurakkas said:
void main()
{
int scores [NUM];
fillarray (scores);
Shouldn't this be int main() instead? Apart from that it seems okay and works.
 
It compiles for me too once you fix the problem Defennder mentioned.
 
interesting..

I changed it to "int main()" but now it just shuts off the compiler. it disappears. I reopen the program and when i compile it shows success but when I run the program everything disappears.
 
my reply

first of all in function int low(int [])

for(x=1;x<NUM;x++)

n i didn't get any syntax errors.

========
$$injan
 
ok. It works now. I changed void main() to int main() and compiled the program on a different computer. It works fine. thanks...
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
6K
Replies
6
Views
2K