Answer
Here is a C program that implements a grading system based on marks. The program prompts the user to enter marks and then displays the corresponding grade. The grading scale includes A, B, C, D, and F. You can modify the grading thresholds as needed. To compile and run the program, save it as `grading_system.c`, compile with `gcc grading_system.c -o grading_system`, and run with `./grading_system`.
Solution
Certainly! Below is a simple C program that implements a grading system based on the rules you might have in mind. Since you didn't provide the specific grading rules, I'll assume a common grading scale for demonstration purposes. You can modify the grading thresholds as needed.
### Grading Scale Example:
- A: 80 - 100
- B: 70 - 79
- C: 60 - 69
- D: 50 - 59
- F: 0 - 49
### C Program Implementation:
```c
#include
char getGrade(float marks) {
if (marks >= 80 && marks <= 100) {
return 'A';
} else if (marks >= 70 && marks < 80) {
return 'B';
} else if (marks >= 60 && marks < 70) {
return 'C';
} else if (marks >= 50 && marks < 60) {
return 'D';
} else if (marks >= 0 && marks < 50) {
return 'F';
} else {
return 'X'; // Invalid marks
}
}
int main() {
float marks;
char grade;
printf("Enter the marks obtained (0-100): ");
scanf("%f", &marks);
grade = getGrade(marks);
if (grade == 'X') {
printf("Invalid marks entered. Please enter a value between 0 and 100.\n");
} else {
printf("The grade for marks %.2f is: %c\n", marks, grade);
}
return 0;
}
```
### Explanation:
1. **Function `getGrade(float marks)`**: This function takes the marks as input and returns the corresponding grade based on the defined grading scale.
2. **Main Function**:
- Prompts the user to enter the marks.
- Calls the `getGrade` function to determine the grade.
- Displays the grade or an error message if the input is invalid.
### How to Compile and Run:
1. Save the code in a file named `grading_system.c`.
2. Open a terminal and navigate to the directory where the file is saved.
3. Compile the program using:
```bash
gcc grading_system.c -o grading_system
```
4. Run the program using:
```bash
./grading_system
```
You can modify the grading thresholds in the `getGrade` function as per the specific requirements provided by Kirinyaga University.
Reviewed and approved by the UpStudy tutoring team
Explain
Simplify this solution