fork(1) download
  1. //C code
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. //Declare variables
  7. char StudentName[100];
  8. float Avg,TotalClasses;
  9. int Students, TotalStudents, Sum, Classes, A, B, C, D, F;
  10. char c;
  11. A=4;
  12. B=3;
  13. C=2;
  14. D=1;
  15. F=0;
  16.  
  17. //This is where the problem begins.
  18. //I want to allow the user to input the number of students
  19. //being graded. "Enter the number of students being graded"
  20. //comes up fine.
  21. printf ("Enter the number of students being graded.");
  22. scanf ("%i", &TotalStudents);
  23.  
  24. //First loop
  25. for (Students = 0; Students<TotalStudents; Students++){
  26. Avg =0.0;
  27. printf ("Enter Student Name \n");
  28. scanf ("%s", StudentName);
  29. printf ("Enter Number of Classes \n");
  30. scanf ("%f", &TotalClasses);
  31. for (Classes = 0; Classes < TotalClasses; Classes++){
  32.  
  33. printf ("Enter Letter Grade for Class \n");
  34. //The second problem starts here. I am trying to find a way to
  35. //allow the user to input the letter grade and add all the grades
  36. //together. After that I want it to find the average for that
  37. //student before moving on to the next student.
  38. //I know my code is completely wrong but I don't know how to correct
  39. //it based off of the examples I have seen
  40. scanf (" %c", &c);
  41. switch(c)
  42. {
  43. case 'A': Sum+=A;
  44. break;
  45. case 'B': Sum+=B;
  46. break;
  47. case 'C': Sum+=C;
  48. break;
  49. case 'D': Sum+=D;
  50. break;
  51. case 'F': Sum+=F;
  52. break;
  53. }
  54.  
  55. }
  56. Avg = Sum/TotalClasses;
  57. printf ("%s's average is %f \n", StudentName, Avg);
  58. }
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 3144KB
stdin
1
Bill
1
A
stdout
Enter the number of students being graded.Enter Student Name 
Enter Number of Classes 
Enter Letter Grade for Class 
Bill's average is 4.000000