I really need help in writing this program for homework.

  1. Round the average for each student to the nearest integer.
  2. Add code to print out an appropriate message for each student. (given in prologue comments)
  3. Add code to calculate the highest student average, and the lowest student average.
  4. Add code to determine the number of students in each message category..
  5. At the conclusion of the while (inData) loop, print out the number of students processed, the highest student average, the lowest student average, and the number of students in each message category.

This is what I have so far, not much but I declared some variables:

// Program processes any number of students. 
// Program inputs student name and test scores from a file.
// It calculates the average of the scores and 
// prints a message depending on the score
//          average >= 95        Oh Yes !
//          average < 60        Oh NO !
//          60 <= average < 95    Okay! 

// Data for each student is on two line
//          first line:<firstname >  <lastname >   <number of scores>
//           second line: integer scores separated by blanks
//        Sample data lines for  one student:
//                        Alec Anderson  5
//                        90 70 88  60   95 


  #include<iostream>
  #include <string>
  #include<fstream>
  #include <iomanip>
 using namespace std ;

  int main()
   {     

          string first, last;
          int sum,     //sum of scores for one student 
              num,   // number of tests for one student 
              score,   // student score
              count,    // loop control variable
              average, // average for one student
              rounded;

         ifstream inData; //input file stream variable

         cout << "Enter first and last name: ";
         cin >> first >> last;

         cout << "\nEnter the number of scores: ";
         cin >> score;

         cout << "\nEnter integer scores separated by blanks: ";
         cin >> score;

         inData.open("Self_paced.txt");                                     
       if( !inData) 
         {
              cout << " input file not found \n";
              system ("pause");
              return 1;
         }   


         inData >> first >> last;
         while (inData ) 
         {
                 // first student 
         inData >> first >> last;
         inData >> num;
         cout <<"Student Name: " <<first<< " " << last  << endl;
         sum = 0;
         count = 1;
         cout <<"Scores:" ;
         while ( count <= num)
         {     inData >> score ;
               cout << score << " ";
               sum = sum + score;
               count++;        
         }

         return'Great';
         rounded =  static_cast<int>(num + 0.5);
         average = sum /num;
         cout << "\naverage = " << average <<endl;
         cout <<"**********************\n";

         inData >> first >> last;
         }

         cout << "\n\nProcessing is complete\n\n\n";
         cout << "The total number of students was " << endl;
         cout << "Number of averages at or above 95 was " << endl;
         cout <<"Number of averages below 60 was " << endl;
         cout << "Number of averages between 94 and 60, inclusive " << endl;

         cout << "The highest average was " << endl;
         cout << "The lowest student average was " << endl;

         cout << endl << endl;
         system ("pause");
         return 0;
   }

Again, please use code tags.

This is a strange program. You have a kind of half attempt at reading something from user input from stdin, then you have a random line that takes some things from infile and then you use a while loop to try and read the file. I think that you only need the stuff in the while loop, not any of the other stuff.

You also have a statement like return 'Great', which makes no sense so you should remove it.

Other than that, it seems to be on track to do what the question asks, so I don't really see what the problem is? Maybe you could be a little more specific on the kind of help that you need?

Also, a further point, you should not use:

istream infile("file.txt");
if(!infile){   // This isn't really very robust or clear
   std::cerr << "ERROR!" << std::endl;
   return 1;
}

instead you should use:

istream infile("file.txt");
if(infile.is_open() == false){   // This actually checks if the file is open, and is clearer to read
   std::cerr << "ERROR!" << std::endl;
   return 1;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.