Advertisement
whitesurge

Lab4 (C compiled in C++)

Sep 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.     float max = 0;
  6.     float score = 0;
  7.     float percentage = -1;
  8.     char quit = 'a';
  9.     char letter = 'F';
  10.     float remainder = 0;
  11.  
  12.     do{
  13.         printf("Max score of your exam: ");
  14.         scanf("%f", &max);
  15.     }while(max == 0);
  16.  
  17.  
  18.     //Potential for a do while loop or a while loop until a valid score is entered
  19.     printf("What is your score: ");
  20.     scanf("%f", &score);
  21.  
  22.     percentage = score/max * 100;
  23.  
  24.     if(score > max) {
  25.         printf("Error, score is invalid. Please reset the board\n");
  26.         goto end;
  27.     }
  28.     else if(percentage >= 90) {
  29.         letter = 'A';
  30.     }
  31.     else if(percentage >= 80) {
  32.         letter = 'B';
  33.     }
  34.     else if(percentage >= 70) {
  35.         letter = 'C';
  36.     }
  37.     else if(percentage >= 60) {
  38.         letter = 'D';
  39.         }
  40.     else{
  41.         letter = 'F';
  42.     }
  43.  
  44.     //Next Letter Grade
  45.     if(percentage < 90) {
  46.         remainder = 10 - ( (int) percentage % 10);
  47.  
  48.         printf("You got a %c, and you were %0.2f%% away from the next letter grade.\n", letter, remainder);
  49.     }else{
  50.         printf("You got a %c, you can not move up a letter grade!\n", letter);
  51.     }
  52.  
  53.  
  54.     end: printf("Program finished, press any key to quit ... ");
  55.     getchar();
  56.     getchar();
  57.     scanf("%c", &quit);
  58.     printf("\nYou pressed %c to quit the program\n", quit);
  59.  
  60.     printf("Goodbye\n");
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement