Simple grading report

joshmo 0 Tallied Votes 478 Views Share

The code prompts the user for a student name and the marks then prints out the report with a letter grade..It also asks the user for the file name and stores the data in the file.

/*Generates a simple grading report for each student*/

#include <stdio.h>

#define LEN 25

#define S 5

struct stud_rec

{

	char name[LEN+1];

	float num_grade;

	char let_grade;

};

struct stud_rec records[S]; 

void letter_grade(double average, double points);

main()

{

	int n,b,i,rec;

	char fname[LEN+1];

	double points,average;

	FILE *fp;

	printf("Please Enter a file name to store the data: ");

	scanf ("%s", &fname);
	
	fp = fopen(fname, "w");

	printf("How many records do you want to enter?: ");

	scanf("%d", &rec);

	for(i=0;i<rec;i++)

	{

		printf("Enter the student name: ");

		scanf("%s", &records[i].name);

		fprintf(fp,"\n%s\n",records[i].name);

		n=0;

		for (b=0;b<S;b++)

		{
			
			n++;

			printf("Enter Grade %d: ",n);

			scanf("%f", &records[b].num_grade);

			fprintf(fp,"%.1f ", records[b].num_grade);

		}

		printf("\n");

		printf("My Grading Report\n");

		printf("Student  Grade1  Grade2  Grade3  Grade4  Grade5  Tpts  FinalGrade  LetterGrade\n");

		printf("--------------------------------------------------------------------------------\n");
	
		printf("%s", records[i].name);

		for (b=0;b<S;b++)

		{

			printf("\t  %.1f",records[b].num_grade);


		}
		
		points=0;
		
		for(b=0;b<S;b++)


		{
			
		
			points=points+records[b].num_grade;
		
		}

		average = (points/S);

		printf("\t %.1f",points);

		printf("\t %.1f", average);

		letter_grade(average,points);
		
		printf("\n");

		printf("--------------------------------------------------------------------------------\n");

		printf("Class Average: %.lf\n\n", average);
	
	}

	fclose(fp);

	return 0;

}

void letter_grade(double average, double points)

{

		
	if (average>=80)

	{

		printf("\t\tA");

	}

	if ((average>=70) && (average<80))

	{
			
		printf("\t\tB");

	}

	if ((average>=60)&&(average<70))

	{

		printf("\t\tC");

	}

	if ((average>=50)&&(average<60))

	{

		printf("\t\tD");

	}

	else if(average<50)

	{

		printf("\t\tF");

	}

}
hacker9801 49 Junior Poster

lol.... that's C not C++

joshmo 8 Posting Whiz in Training

ooops sorry ma bad...

MPELANE 0 Unverified User

This is a good work man, even though i don't know nothing about any other programming language except pseudocode.the reason is because im first year in nwu.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.