logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/h3sol/grade.c

/*

grade.c - enter points earned and points possible, 
		  displays the users percent and grade.

*/

#include <stdio.h>

int main(){

	//variable declarations
	float earned, possible, total;

	//ask how many points did the student get
	printf("How many points did this student earn?> ");
	scanf("%f", &earned); //using scanf to get the value

	//asking how many points were possible,
	printf("How many points were possible?> "); 
	scanf("%f", &possible); //using scanf to get that value

	total = 100 * (earned/possible); //calculate the total, then multiply by 100
									 //to get the percent value

	printf("The student got a %.2f percent\n", total); //print the percent value

	//now do the if-else statements here
	if(total >= 90)
		printf("This is an A\n");
	else if(total >= 80)
		printf("This is a B\n");
	else if(total >= 70)
		printf("This is a C\n");
	else if(total >= 60)
		printf("This is a D\n");
	else
		printf("This student failed\n");


	return 0;

}