Menu
Coddy logo textTech

Recap: Student Data Struct

Part of the Logic & Flow section of Coddy's C journey — lesson 43 of 63.

challenge icon

Challenge

Easy

Create a C program that demonstrates the complete workflow of struct usage with a student management system. Your program should:

  1. Define a struct named Student with the following members:
    • An integer id to store the student's ID number
    • A float grade to store the student's grade
  2. In the main function, create a Student variable named student1
  3. Read the student's ID and grade from input using scanf:
    • Read an integer for the ID and store it in student1.id
    • Read a float for the grade and store it in student1.grade
  4. After reading the input, perform the following validation and calculations:
    • If the grade is greater than 100.0, set it to 100.0
    • If the grade is less than 0.0, set it to 0.0
    • Calculate a bonus grade by adding 5.0 to the current grade (after validation)
    • If the bonus grade exceeds 100.0, set the bonus grade to 100.0
  5. Print the student information in this exact format:
    • Student Information:
    • ID: [id]
    • Original Grade: [grade]
    • Bonus Grade: [bonus_grade]
    • Grade Status: [status]
  6. The grade status should be determined as follows:
    • If the original grade is 90.0 or above: Excellent
    • If the original grade is 80.0 to 89.9: Good
    • If the original grade is 70.0 to 79.9: Average
    • If the original grade is below 70.0: Needs Improvement

This challenge tests your understanding of struct definition, variable creation, member access using the dot operator, input handling with scanf, and conditional logic for data validation and processing. You'll practice the complete workflow of working with structs in a practical scenario.

Try it yourself

#include <stdio.h>

// TODO: Define the Student struct here

int main() {
    // TODO: Create a Student variable named student1
    
    // Read input
    int id;
    float grade;
    scanf("%d", &id);
    scanf("%f", &grade);
    
    // TODO: Store the input values in the struct members
    
    // TODO: Implement grade validation and bonus calculation
    
    // TODO: Determine grade status
    
    // Output the results
    printf("Student Information:\n");
    printf("ID: %d\n", /* TODO: print student ID */);
    printf("Original Grade: %.1f\n", /* TODO: print original grade */);
    printf("Bonus Grade: %.1f\n", /* TODO: print bonus grade */);
    printf("Grade Status: %s\n", /* TODO: print grade status */);
    
    return 0;
}

All lessons in Logic & Flow