When I compile this in linux I get an error:
project9v2.c: In function `main`:
project9v2.c:34:33: error: expected expression before `<=` token
project9v2.c:38:33: error: expected expression before `<=` token
project9v2.c:42:33: error: expected expression before `<=` token
project9v2.c:46:33: error: expected expression before `<=` token
It scans the file a.txt
and is supposed to output to b.txt
. The contents of a.txt
are:
97 85 70 84 33 100 283 53 81 69 89 73 65 86 77 556 -1
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inFile, *outFile;
int current;
int sum = 0, b, i;
int A=0, B=0, C=0, D=0, F=0;
int theGrades[100];
inFile = fopen("a.txt", "r");
outFile = fopen("b.txt", "w");
if (inFile != NULL)
{
b = fscanf(inFile, "%d", ¤t);
}
while(b != -1)
{
theGrades[sum] = current;
sum++;
b = fscanf(inFile, "%d", ¤t);
}
for(i=0; i<sum; i++)
{
if (theGrades[i] <0)
{
break;
}
else if (theGrades[i] >=90 && <=100)
{
A++;
}
else if (theGrades[i] >=80 && <=89)
{
B++;
}
else if (theGrades[i] >=70 && <=79)
{
C++;
}
else if (theGrades[i] >=60 && <=69)
{
D++;
}
else
{
F++;
}
}
fprintf(outFile, "The total number of grades is:" , sum);
fprintf(outFile, "Number of A’s = %d\n" ,A);
fprintf(outFile, "Number of B’s = %d\n" ,B);
fprintf(outFile, "Number of C’s = %d\n" ,C);
fprintf(outFile, "Number of D’s = %d\n" ,D);
fprintf(outFile, "Number of F’s = %d\n" ,F);
fclose(inFile);
fclose(outFile);
}
following c syntax, you should modify it like below. :) compare operator should be used between two variable or number.
else if (theGrades[i] >=90 && theGrades[i]<=100)
{
A++;
}
else if (theGrades[i] >=80 && theGrades[i]<=89)
{
B++;
}
else if (theGrades[i] >=70 && theGrades[i]<=79)
{
C++;
}
else if (theGrades[i] >=60 && theGrades[i]<=69)