Advertisement
whitesurge

C Lab6

Oct 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main()
  7. {
  8.     int loop =14;
  9.     int NumberOfExams = 3;
  10.     float max = 100.00;
  11.     float score[NumberOfExams];
  12.     float percentage = -1;
  13.     char quit = 'a';
  14.     char letter = 'F';
  15.     float total = 0;
  16.     float avg = 0;
  17.     char name[20];
  18.     //int i = 0;
  19.     int safety = 0;
  20.     int command = 0;
  21.  
  22.  
  23.  
  24.     while(loop == 14){
  25.  
  26.  
  27.         printf("1. Enter name\n");
  28.         printf("2. Enter Exams\n");
  29.         printf("3. Display Average Exam Score\n");
  30.         printf("4. Display Summary\n");
  31.         printf("5. Quit\n");
  32.         scanf("%d",&command);
  33.  
  34.         if (command == 1){
  35.             printf("Please enter your first name: ");
  36.             scanf("%s", &name);
  37.             //scanf("%[^\n]s",&name);
  38.         }
  39.  
  40.         if(command == 2){
  41.             for(int i = 0; i<NumberOfExams ;i++){
  42.  
  43.                 printf("What is your score: ");
  44.  
  45.                 scanf("%f", &score[i]);
  46.  
  47.                 if(score[i] > max) {
  48.  
  49.                     printf("Error, score is invalid. Please reset the board\n");
  50.                     goto end;
  51.  
  52.                 }
  53.  
  54.             }
  55.  
  56.             for(int i = 0; i<NumberOfExams ; i++){
  57.  
  58.                 total = total + score[i];
  59.  
  60.             }
  61.  
  62.             avg = total/NumberOfExams;
  63.  
  64.             percentage = avg/max * 100.00;
  65.  
  66.             if(avg > max) {
  67.  
  68.                 printf("Error, score is invalid. Please reset the board\n");
  69.                 goto end;
  70.  
  71.             }
  72.  
  73.             else if(percentage >= 90) {
  74.  
  75.                 letter = 'A';
  76.  
  77.             }
  78.  
  79.             else if(percentage >= 80) {
  80.  
  81.                 letter = 'B';
  82.  
  83.             }
  84.  
  85.             else if(percentage >= 70) {
  86.  
  87.                 letter = 'C';
  88.  
  89.             }
  90.  
  91.             else if(percentage >= 60) {
  92.  
  93.                 letter = 'D';
  94.  
  95.             }
  96.  
  97.             else{
  98.  
  99.                 letter = 'F';
  100.  
  101.             }
  102.         }
  103.  
  104.         if(command == 3){
  105.             printf("Your average is %0.2f%%", avg);
  106.         }
  107.  
  108.  
  109.  
  110.         if(command == 4){
  111.             printf("Hello, %s, based on your exams of %0.2f%%, %0.2f%%, and %0.2f%%. Your average was %0.2f%% with a letter grade of %c.\n", name, score[0], score[1], score[2],avg ,letter);
  112.         }
  113.  
  114.         if(command == 5){
  115.             loop = 49;
  116.             goto end;
  117.         }
  118.  
  119.         safety++;
  120.  
  121.         if(safety>20){
  122.             break;
  123.         }
  124.     }
  125.  
  126.     end: printf("Program finished, press any key to quit ... ");
  127.  
  128.     getchar();
  129.     getchar();
  130.  
  131.     scanf("%c", &quit);
  132.  
  133.     printf("\nYou pressed %c to quit the program\n", quit);
  134.  
  135.     printf("Goodbye\n");
  136.  
  137.  
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement