emaansahmed

Assignment #3 Part 1

Apr 26th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  int main()
  9.  
  10.  {
  11.      int grade;
  12.      int counter = 0;
  13.      int aValue = 0;
  14.      int bValue = 0;
  15.      int cValue = 0;
  16.      int dValue = 0;
  17.      int fValue = 0;
  18.      double total = 0;
  19.  
  20.      cout << "Enter last semesters grades: " << endl;
  21.      
  22.      while ( (grade = cin.get() ) != EOF )
  23.  
  24.      {
  25.      
  26.         switch (grade)
  27.         {
  28.         case 'A':
  29.         case 'a':
  30.             aValue += 4;
  31.             counter += 1;
  32.             break;
  33.  
  34.          case 'B':
  35.          case 'b':
  36.              bValue += 3;
  37.              counter += 1;
  38.              break;
  39.          
  40.          case 'C':
  41.          case 'c':
  42.              cValue += 2;
  43.              counter += 1;
  44.              break;
  45.  
  46.          case 'D':
  47.          case 'd':
  48.              dValue +=1;
  49.              counter += 1;
  50.              break;
  51.  
  52.          case 'F':
  53.          case 'f':
  54.              fValue += 0;
  55.              counter += 1;
  56.              break;
  57.  
  58.          case '\n':
  59.          case ' ':
  60.              break;
  61.  
  62.          default:
  63.              cout << "Incorrect letter grade" << endl;
  64.              break;
  65.         }
  66.      }   
  67.      
  68.      total = aValue + bValue + cValue + dValue + fValue;
  69.      cout << setprecision(2) << fixed << total/counter  << endl;
  70.  
  71.    
  72.     system ("pause");
  73.     return 0;
  74.  
  75.  }
Advertisement
Add Comment
Please, Sign In to add comment