Advertisement
Lawnknome

grades.cpp

Nov 7th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. void grade (int grades[], int size);
  6.  
  7. int main()
  8. {  
  9.     int grades[] = {0,0,0,0,0,0};
  10.     int size = (sizeof(grades)/sizeof(grades[0]));
  11.  
  12.     cout << "\nThis program will prompt for a single grade at a time, please hit enter after each grade.\n";
  13.  
  14.     grade(grades, size);
  15.  
  16.     cout << "\nAll scores have been tallied and ordered." << endl;
  17.     cout << "Here is the breakdown of the scores." << endl;
  18.  
  19.  
  20.     for(int x = 0; x < size; x++)
  21.     {
  22.         cout << grades[x] << " grade(s) of " << x << "." << endl;
  23.     }  
  24.    
  25.     return 0;
  26. }
  27.  
  28.  
  29. void grade (int grades[], int size)
  30. {
  31.     int score;
  32.     char scores[10];   
  33.  
  34.     do
  35.     {  
  36.         cout << "\nIf you are done entering scores, please enter \"X\" when prompted for the next score." << endl;
  37.         cout << "\nPlease enter the next grade on the scale of 0 to 5: ";
  38.         cin >> scores;
  39.         cin.ignore();
  40.  
  41.         if(scores[0] == 'X' || scores[0] == 'x')
  42.             return;
  43.  
  44.         score = atoi(scores);
  45.  
  46.         if(score >= 0 && score <=5)
  47.         {  
  48.             switch(score)
  49.             {
  50.                 case 0:
  51.            
  52.                     grades[0] += 1;
  53.                     break;
  54.  
  55.                 case 1:
  56.  
  57.                     grades[1] += 1;
  58.                     break;
  59.  
  60.                 case 2:
  61.  
  62.                     grades[3] += 1;
  63.                     break;
  64.  
  65.                 case 3:
  66.  
  67.                     grades[4] += 1;
  68.                     break;
  69.  
  70.                 case 4:
  71.  
  72.                     grades[4] += 1;
  73.                     break;
  74.  
  75.                 case 5:
  76.  
  77.                     grades[5] += 1;
  78.                     break;
  79.             }
  80.  
  81.         }
  82.        
  83.         else if(score < 0 || score > 5)
  84.  
  85.             cout << "\nPlease enter a score between 0 and 5." << endl;
  86.    
  87.     }while(!(scores[0] == 'X'   || scores[0] == 'x'));
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement