Advertisement
Guest User

finale

a guest
Dec 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.83 KB | None | 0 0
  1. /*
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. void clearMem() {
  7.     int c = getchar();
  8.     while (c != EOF && c != '\n')
  9.         c = getchar();
  10. }
  11.  
  12. struct studentInfo {
  13.     float gpa[1];
  14.     char name[42];
  15.     char grades[5];
  16.     int hours[5];
  17.     float gradePoint[5];
  18. };
  19.  
  20. float gpaCalculator(struct studentInfo *calculator);
  21. //float converter(char grades[]);
  22. float converter(char grades);
  23.  
  24. /*
  25. float converter(struct studentInfo *calculator) {
  26.     int i;
  27.     for (i = 0; i < 5;i++) {
  28.         if (calculator->grades[i] == 'A')
  29.         {
  30.             return 4;
  31.         }
  32.         else if (calculator->grades[i] == 'B')
  33.         {
  34.             return 3;
  35.         }
  36.         else if (calculator->grades[i] == 'C')
  37.         {
  38.             return 2;
  39.         }
  40.         else if (calculator->grades[i] == 'D')
  41.         {
  42.             return 1;
  43.         }
  44.         else if (calculator->grades[i] == 'F')
  45.         {
  46.             return 0;
  47.         }
  48.         else
  49.         {
  50.             return 0;
  51.         }
  52.     }
  53. }
  54. */
  55.  
  56. float converter(char grades){
  57.     int i;
  58.     for (i = 0; i < 5;i++) {
  59.         if (grades == 'A')
  60.         {
  61.             return 4;
  62.         }
  63.         else if(grades == 'B')
  64.         {
  65.             return 3;
  66.         }
  67.         else if (grades == 'C')
  68.         {
  69.             return 2;
  70.         }
  71.         else if (grades == 'D')
  72.         {
  73.             return 1;
  74.         }
  75.         else if (grades == 'F')
  76.         {
  77.             return 0;
  78.         }
  79.         else
  80.         {
  81.             return 0;
  82.         }
  83.     }
  84.     return grades;
  85. }
  86.  
  87. float gpaCalculator(struct studentInfo *calculator)
  88. {
  89.     int i = 0;
  90.     int totalHours = 0;
  91.     float totalGradePoints = 0;
  92.    
  93.     calculator->gradePoint[i] = (calculator->hours[i] * converter(calculator->grades[i]));
  94.  
  95.     for (i = 0; i<5;i++) {
  96.         totalHours += calculator->hours[i];
  97.         totalGradePoints += (calculator->hours[i] * converter(calculator->grades[i]));
  98.     }
  99.  
  100.     calculator->gpa[i] = (totalGradePoints) / totalHours;
  101.     printf("\n\nyour hours is : %d", calculator->hours);
  102.     printf("\n\nyour grades is : %s", calculator->grades);
  103.     printf("\n\nyour total hours is : %d", totalHours);
  104.     printf("\n\nyour total grades is : %.2f", totalGradePoints);
  105.     printf("\n\nyour average is : %.2f\n\n", calculator->gpa[i]);
  106.     return 0;
  107. }
  108.  
  109. int main()
  110. {
  111.     int i;
  112.     int j;
  113.     int numberOfStudents=0;
  114.     int numberOfCourses = 5;
  115.     struct studentInfo* bigPointer;
  116.     printf("Hello and welcome to the gpa calculator program!\n\n");
  117.     printf("please enter the number of students in the class: \n");
  118.     fgets(numberOfStudents, 10, stdin);
  119.    
  120.     bigPointer = (struct studentInfo*)malloc(numberOfStudents * sizeof(struct studentInfo));
  121.     for (i = 0; i < numberOfStudents; i++)
  122.     {
  123.         printf("Please enter the name of student number %d: \n", i + 1);
  124.         fgets(bigPointer[i].name,42,stdin);
  125.         for (j = 0; j < numberOfCourses; j++)
  126.         {
  127.             printf("please enter grade number %d \n", j + 1);
  128.             fgets(bigPointer[i].grades[j], 5, stdin);
  129.            
  130.             printf("please enter the hours spent on that grade: \n");
  131.             fgets(bigPointer[i].hours[j], 2, stdin);
  132.            
  133.         }
  134.         gpaCalculator(&bigPointer[i]);
  135.         printf("\n\nyour average is : %.2f\n\n", &bigPointer[i].gpa);
  136.  
  137.     }
  138.     free(bigPointer);
  139.  
  140.     return 0;
  141. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement