Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #include <stdio.h>
- #include <stdlib.h>
- void clearMem() {
- int c = getchar();
- while (c != EOF && c != '\n')
- c = getchar();
- }
- struct studentInfo {
- float gpa[1];
- char name[42];
- char grades[5];
- int hours[5];
- float gradePoint[5];
- };
- float gpaCalculator(struct studentInfo *calculator);
- //float converter(char grades[]);
- float converter(char grades);
- /*
- float converter(struct studentInfo *calculator) {
- int i;
- for (i = 0; i < 5;i++) {
- if (calculator->grades[i] == 'A')
- {
- return 4;
- }
- else if (calculator->grades[i] == 'B')
- {
- return 3;
- }
- else if (calculator->grades[i] == 'C')
- {
- return 2;
- }
- else if (calculator->grades[i] == 'D')
- {
- return 1;
- }
- else if (calculator->grades[i] == 'F')
- {
- return 0;
- }
- else
- {
- return 0;
- }
- }
- }
- */
- float converter(char grades){
- int i;
- for (i = 0; i < 5;i++) {
- if (grades == 'A')
- {
- return 4;
- }
- else if(grades == 'B')
- {
- return 3;
- }
- else if (grades == 'C')
- {
- return 2;
- }
- else if (grades == 'D')
- {
- return 1;
- }
- else if (grades == 'F')
- {
- return 0;
- }
- else
- {
- return 0;
- }
- }
- return grades;
- }
- float gpaCalculator(struct studentInfo *calculator)
- {
- int i = 0;
- int totalHours = 0;
- float totalGradePoints = 0;
- calculator->gradePoint[i] = (calculator->hours[i] * converter(calculator->grades[i]));
- for (i = 0; i<5;i++) {
- totalHours += calculator->hours[i];
- totalGradePoints += (calculator->hours[i] * converter(calculator->grades[i]));
- }
- calculator->gpa[i] = (totalGradePoints) / totalHours;
- printf("\n\nyour hours is : %d", calculator->hours);
- printf("\n\nyour grades is : %s", calculator->grades);
- printf("\n\nyour total hours is : %d", totalHours);
- printf("\n\nyour total grades is : %.2f", totalGradePoints);
- printf("\n\nyour average is : %.2f\n\n", calculator->gpa[i]);
- return 0;
- }
- int main()
- {
- int i;
- int j;
- int numberOfStudents=0;
- int numberOfCourses = 5;
- struct studentInfo* bigPointer;
- printf("Hello and welcome to the gpa calculator program!\n\n");
- printf("please enter the number of students in the class: \n");
- fgets(numberOfStudents, 10, stdin);
- bigPointer = (struct studentInfo*)malloc(numberOfStudents * sizeof(struct studentInfo));
- for (i = 0; i < numberOfStudents; i++)
- {
- printf("Please enter the name of student number %d: \n", i + 1);
- fgets(bigPointer[i].name,42,stdin);
- for (j = 0; j < numberOfCourses; j++)
- {
- printf("please enter grade number %d \n", j + 1);
- fgets(bigPointer[i].grades[j], 5, stdin);
- printf("please enter the hours spent on that grade: \n");
- fgets(bigPointer[i].hours[j], 2, stdin);
- }
- gpaCalculator(&bigPointer[i]);
- printf("\n\nyour average is : %.2f\n\n", &bigPointer[i].gpa);
- }
- free(bigPointer);
- return 0;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement