C/C++ Resolving a CPP 6 Syntax Error - Declaration syntax error

  • Thread starter Thread starter ozgurakkas
  • Start date Start date
  • Tags Tags
    Error
AI Thread Summary
The discussion centers on resolving a "Declaration syntax error" in a C++ program related to the function declaration "int low(int [])". The main issue identified is the use of "void main()" instead of the standard "int main()", which is necessary for proper program execution. After changing "void main()" to "int main()", the program initially caused the compiler to shut down unexpectedly. However, after recompiling on a different computer, the program worked correctly. The resolution highlights the importance of using the correct main function signature in C++ to avoid runtime issues.
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...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top