I'm currently trying to edit this program so that it would read 4 inputs on the first line of data, instead of one. All other lines contains just 1 input. I created a program to assign a letter grade to an integer score. This was my first data file:
95
85
80
75
70
68
50
104
-10
and this is my new data file:
90 80 70 60
95
85
80
75
70
68
50
104
-10
I am trying to read in the first 4 inputs on the first line as minimum grades for A, B, C, & D.
When running the program, this is my expected output:
95: A
85: B
80: B
75: C
70: C
68: D
50: F
104: illegal score
-10: illegal score
Here are the other parts of the program:
/* A program to assign letter grades to scores */
#include <stdio.h>
int main()
{
/* Declare variables */
int score;
char grade;
/* While the score input is equal to one */
while(scanf("%d", &score) == 1)
{
/* Print score input */
printf("%d: ", score);
/* Call function to convert score into letter grade */
grade = assign_grade(score);
if (grade == '?')
{
printf("illegal score\n");
}
else
{
/* Print letter grade */
printf("%c\n", grade);
}
}
}
/* Header file declaring assign_grade utility function */
char assign_grade(int score);
/* Given : Number score (integer)
* Return: Letter grade (character)
*/
/* This file contains grader.c's utility function to assign a
* character grade, given an integer score at input */
#include "assign_grade.h"
char assign_grade(int score)
/* Given : Number score (integer)
* Return: Letter grade (character)
*/
{
/* Variable declarations */
char grade;
if (score <= 100 && score >= 90)
{
grade = 'A';
}
if (score <= 89 && score >= 80)
{
grade = 'B';
}
if (score <= 79 && score >= 70)
{
grade = 'C';
}
if (score <= 69 && score >=60)
{
grade = 'D';
}
if (score <= 59 && score >= 0)
{
grade = 'F';
}
if (score < 0 || score > 100)
{
grade = '?';
}
return grade;
}
I am extremely lost. Will someone please suggest any tips or hints?