hey guys im trying to get my program to test if a line of numbers from a ".dat" file is largest to smallest like 80 75 64 35. if it is then it should not count those as grades. it will count and assign grades to each score from a new line. if the set of numbers on the line are not from largest to smallest then it should stop and print a message. my program works within the bounds of 0-100 and anything out of those numbers are not grades.
main:
Code:
#include <stdio.h>
char assign_grade(int score);
int main()
{
/* declarations */
int score,good=0, bad=0, out=0;
char grade, illegal = 'Z';
/* keep getting input till EOF */
while(scanf("%d", &score) != EOF)
{
/* if within the bounds */
if (score>=0 && score<=100)
{
/* counts and prints passing grades */
if (score >= 70 && score <= 100)
{
good = good + 1;
printf("%d: ", score);
grade = assign_grade(score);
printf("%c\n", grade);
}
/* counts and prints failing grades */
if (score >= 0 && score <= 69)
{
bad = bad + 1;
printf("%d: ", score);
grade = assign_grade(score);
printf("%c\n", grade);
}
}
/* count and prints illegal scores */
if (score<0||score>100)
{
printf("%d: ", score);
printf("illegal score!\n");
out = out + 1; /* counts illegal */
}
}
/* print total count of pass/fail/illegal grades */
printf("Passing scores: %d\n", good);
printf("Failing scores: %d\n", bad);
printf("Illegal scores: %d\n", out);
}
function:
Code:
/* bounds for A/B/C/D/F/Illegal */
#define ISA(c) (c>=90&&c<=100)
#define ISB(c) (c>=80&&c<=89)
#define ISC(c) (c>=70&&c<=79)
#define ISD(c) (c>=60&&c<=69)
#define ISF(c) (c>=0&&c<=59)
#define ISN(c) (c<0&&c>100)
/* assignment function */
char assign_grade(int score)
{
/* testing scores and returning grade */
if (ISA(score))
return 'A';
if (ISB(score))
return 'B';
if (ISC(score))
return 'C';
if (ISD(score))
return 'D';
if (ISF(score))
return 'F';
if (ISN(score))
return 'Z';
}
dat:
Code:
75 80 70 60
95
85
80
75
70
68
50
104
-10
dat2:
Code:
90 80 70 60
95
85
80
75
70
68
50
104
-10