Resolving a CPP 6 Syntax Error - Declaration syntax error

  • C/C++
  • Thread starter ozgurakkas
  • Start date
  • Tags
    Error
In summary, the conversation is about a program that has been created with an error message "Declaration syntax error" in CPP 6, specifically in the function "int low(int [])". The person is seeking help to fix this error, and after receiving suggestions to change "void main()" to "int main()", they were able to successfully compile the program on a different computer.
  • #1
15
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
  • #2
ozgurakkas said:
void main()
{
int scores [NUM];
fillarray (scores);
Shouldn't this be int main() instead? Apart from that it seems okay and works.
 
  • #3
It compiles for me too once you fix the problem Defennder mentioned.
 
  • #4
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.
 
  • #5
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
 
  • #6
ok. It works now. I changed void main() to int main() and compiled the program on a different computer. It works fine. thanks...
 

1. What does a CPP 6 syntax error mean?

A CPP 6 syntax error is an error that occurs when the syntax of a C++ program does not follow the correct structure or grammar rules. This can happen when there is a missing or misplaced character, incorrect spacing, or invalid use of keywords or operators.

2. How do I know where the syntax error is in my code?

The compiler will usually give an error message that includes the line number and the specific error that occurred. By looking at the line number and the code on that line, you can identify the location of the syntax error.

3. How can I fix a CPP 6 syntax error?

The first step is to carefully read the error message and identify the location of the error. Then, check your code for any obvious mistakes such as missing semicolons or incorrect syntax. If you are unable to find the error, you can try using a debugger or asking for help from a more experienced programmer.

4. Can a single syntax error cause multiple errors in my code?

Yes, a single syntax error can cause multiple errors in your code. This is because the compiler will stop at the first error it encounters, and subsequent lines of code may not work properly due to the missing or incorrect syntax.

5. How can I prevent CPP 6 syntax errors from occurring?

The best way to prevent syntax errors is to carefully follow the syntax rules of the C++ language. This includes using proper spacing, correct use of keywords and operators, and proper placement of braces and semicolons. It is also helpful to use an IDE or code editor that has a syntax highlighting feature, which can catch some syntax errors as you write your code.

Suggested for: Resolving a CPP 6 Syntax Error - Declaration syntax error

Replies
0
Views
101
Replies
1
Views
910
Replies
23
Views
4K
Replies
13
Views
1K
Replies
32
Views
1K
Replies
14
Views
1K
Replies
3
Views
1K
Replies
2
Views
2K
Back
Top