Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- const int MAX = 600;
- double average(int sum, int quantity);
- int main() {
- string name[MAX];
- int grade[MAX];
- int quantity = 0;
- int x = 0;
- double avg = 0;
- int sum = 0;
- ifstream inFS;
- int inFile = 0; // Data value from file
- inFS.open("indata3.txt");
- if (!inFS.is_open()) {
- cout << "Could not open file myfile.txt." << endl;
- return 1; // 1 indicates error
- }
- while (!inFS.eof())
- {
- cin >> name[x] >> grade[x];
- x++;
- }
- cout << "Enter quantity of grades to be processed ("<< x<< "): " << endl;
- cin >> quantity;
- for (x = 0; x < quantity; x++)
- {
- sum = sum + grade[x];
- }
- avg = average(sum, quantity);
- cout << "Average grade: " << avg;
- for (x = 0; x<quantity; x++) {
- cout << "Name" << name[x] << " Grade: " << grade[x] << "Comments: ";
- if (grade[x]<avg) {
- cout << " below average" << endl;
- }
- else if (grade[x] > avg) {
- cout << " above average" << endl;
- }
- else {
- cout << " average" << endl;
- }
- }
- return 0;
- }
- double average(int sum, int quantity)
- {
- int avg = 0;
- avg = sum / quantity;
- return avg;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement