Function Convert Grade

PHOTO EMBED

Tue Jun 11 2024 05:19:27 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c #function

#include<stdio.h>

char convert_percent_to_grade(float input)
{
    if(input>=80.0f)
    {
        return 'A';
    }
    else if(input>=60.0f && input <80.0f)
    {
        return 'B';
    }
    else if(input>=50.0f && input < 60.0f)
    {
        return 'C';
    }
    else 
    {
        return 'D';
    }

}

int main()
{
    float input;
    
    printf("What's the percentage:\n");
    scanf("%f",&input);
    
    char output = convert_percent_to_grade(input);
    
    printf("%.2f%% is %c Grade",input,output);
    
    
}
content_copyCOPY

Objective: Develop a program that translates a percentage value into a corresponding letter grade based on the given grade distribution. Guidelines: Function Declaration & Definition: convert_percent_to_grade Function: Input: A real number (float or double) representing a percentage. Output: A character value corresponding to a letter grade. Logic: The function should determine the letter grade according to the provided table: Greater than or equal to 80% => 'A' Greater than or equal to 65% => 'B' Greater than or equal to 50% => 'C' Greater than or equal to 0% => 'D' The function should be free from side effects; it should not print or read from the keyboard. Main Program Execution: Within the main function: Prompt the user to input a percentage value. Retrieve and store the user's input. Call the convert_percent_to_grade function with the stored percentage value. Print the returned letter grade from the function. For example: Input Result 55 What's the percentage: 55.00% is C Grade