PDA

View Full Version : Where is the error I can't find it


toryadamz
Feb 28, 2007, 09:00 AM
where is the error? It says this:
grades.c: In function `main':
grades.c:7: error: array size missing in `grade'
grades.c:7: error: conflicting types for `grade'
grades.c:7: error: previous declaration of `grade'
grades.c:58: error: subscripted value is neither array nor pointer
grades.c:59: error: subscripted value is neither array nor pointer
grades.c:61: error: subscripted value is neither array nor pointer
grades.c:62: error: subscripted value is neither array nor pointer
grades.c:64: error: subscripted value is neither array nor pointer
grades.c:65: error: subscripted value is neither array nor pointer
grades.c:71: error: syntax error before "int"
grades.c:77: error: syntax error before ')' token
grades.c:80: error: subscripted value is neither array nor pointer
grades.c:81: error: subscripted value is neither array nor pointer
grades.c:81: error: subscripted value is neither array nor pointer
grades.c:83: error: subscripted value is neither array nor pointer
grades.c:83: error: subscripted value is neither array nor pointer
grades.c:85: error: subscripted value is neither array nor pointer
grades.c:85: error: subscripted value is neither array nor pointer
grades.c:87: error: subscripted value is neither array nor pointer
grades.c:87: error: subscripted value is neither array nor pointer
grades.c:89: error: subscripted value is neither array nor pointer
grades.c:89: error: subscripted value is neither array nor pointer

SOURCE CODE:





#include<stdio.h>
#include<math.h>

main()
{

int j, c, grade[], number_of_grades, sum, I, grade, grade_total = 0, failure_count = 0;
double pow(double x, double y);
double sqrt(double x);
double standard_dev;
float average, variance, high, low;

printf("How many grades will you be entering?"
"(must be in between 0 and 100");
scanf("%i", &number_of_grades);

if ( number_of_grades < 0 || number_of_grades > 100){
printf("ERROR: You have entered a number to large"
"or to small for the program to calculate"
"number must be in between 0 and 100, and"
"must be a whole number.\n");
return 0;
}



for(I=1; I <= number_of_grades; ++i )
{
printf("Enter grade #%i:", I);
scanf("%i", &grade );

if (grade < 0){
printf("ERROR: You have entered a number"
"not within the domain.\n");
return 0;}
if (grade > 100){
printf("ERROR: You have entered a number"
"not within the domain.\n");
return 0;}

grade_total = grade_total + grade;

if ( grade < 65 )
++failure_count;



average = (float) grade_total / number_of_grades;

sum = 0;
for (I=0;i<=number_of_grades-1;++i){
sum = sum + pow((grade - average),2);
}
variance = sum / (number_of_grades - 1);

standard_dev = sqrt(variance);

high = grade[0];
low = grade[0];
for( I=1;i<=number_of_grades -1;++i ){
if (grade[i] > high){
high = grade[i];
}
if (grade[i] < low){
low = grade[i];
}

}

int c[5]
int c[4]
int c[3]
int c[2]
int c[1]
int c[0]

for (j=0; j<=4; ++j){
c [j]=0}
for (I=0; I<= number_of_grades-1;++i){
if (grade[i] > 89)
c[0] = c[0] + 1;
else if (grade > 79)
c[1] = c[1] + 1;
else if (grade > 69)
c[2] = c[2] + 1;
else if (grade > 59)
c[3] = c[3] + 1;
else
c[4] = c[4] + 1;
}









printf("\nGrade average = %.2f\n", average );
printf("Number of failures = %i\n", failure_count );

return 0;



}

toryadamz
Feb 28, 2007, 09:33 AM
Never mind people I figured it out

asterisk_man
Feb 28, 2007, 09:36 AM
First error is that grade[] requires a number for the size of the array, like grade[10].
Also, you can't define an array and an int with the same name "grade".

Hard to find the next errors since you didn't include line numbers. I can tell you there are places where you use grade by itself without any index.

Fix these errors and try again.

toryadamz
Feb 28, 2007, 09:41 AM
k here is what I am down to
it says I have an error at the very end of the program

1.#include<stdio.h>
2.#include<math.h>
3.
4.main()
{

int j, c, scores[100], number_of_grades, sum, I, grade, grade_total = 0, failure_count = 0;
double pow(double x, double y);
double sqrt(double x);
double standard_dev;
float average, variance, high, low;

printf("How many grades will you be entering?"
"(must be in between 0 and 100");
scanf("%i", &number_of_grades);

if ( number_of_grades < 0 || number_of_grades > 100){
printf("ERROR: You have entered a number to large"
"or to small for the program to calculate"
"number must be in between 0 and 100, and"
"must be a whole number.\n");
return 0;
}



for(I=1; I <= number_of_grades; ++i )
{
printf("Enter grade #%i:", I);
scanf("%i", &grade );

if ( grade = -9 ){
printf("END OF STATS\n");
return 0;
}

else if (grade < 0 || grade > 100)
{

asterisk_man
Feb 28, 2007, 10:56 AM
Looks like your program is cut off before the end. Can you paste it again or point to which line above the error is supposed to be on? Also, always give the entire error message so I know what to look for.

Thanks