Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- void grade (int grades[], int size);
- int main()
- {
- int grades[] = {0,0,0,0,0,0};
- int size = (sizeof(grades)/sizeof(grades[0]));
- cout << "\nThis program will prompt for a single grade at a time, please hit enter after each grade.\n";
- grade(grades, size);
- cout << "\nAll scores have been tallied and ordered." << endl;
- cout << "Here is the breakdown of the scores." << endl;
- for(int x = 0; x < size; x++)
- {
- cout << grades[x] << " grade(s) of " << x << "." << endl;
- }
- return 0;
- }
- void grade (int grades[], int size)
- {
- int score;
- char scores[10];
- do
- {
- cout << "\nIf you are done entering scores, please enter \"X\" when prompted for the next score." << endl;
- cout << "\nPlease enter the next grade on the scale of 0 to 5: ";
- cin >> scores;
- cin.ignore();
- if(scores[0] == 'X' || scores[0] == 'x')
- return;
- score = atoi(scores);
- if(score >= 0 && score <=5)
- {
- switch(score)
- {
- case 0:
- grades[0] += 1;
- break;
- case 1:
- grades[1] += 1;
- break;
- case 2:
- grades[3] += 1;
- break;
- case 3:
- grades[4] += 1;
- break;
- case 4:
- grades[4] += 1;
- break;
- case 5:
- grades[5] += 1;
- break;
- }
- }
- else if(score < 0 || score > 5)
- cout << "\nPlease enter a score between 0 and 5." << endl;
- }while(!(scores[0] == 'X' || scores[0] == 'x'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement