PLEASE someone help me

This is a discussion on PLEASE someone help me within the C++ Programming forums, part of the General Programming Boards category; I have been trying and trying to get this program to work and I just can not seem to get ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    38

    PLEASE someone help me

    I have been trying and trying to get this program to work and I just can not seem to get it

    I can input 3 scores and the average works correctly but it will not print out the 3 scores correctly I have tried everything i can think of
    can someone please help me at least show me what to look at

    when case 2 is selected it prints a -1 so i think somehow it is not storing it correctly

    when case 4 is selected it prints out the first exam score and the correct average but a -1 for the other exam scores.
    I am so confused, I thought I had this,
    I am now begging for help!

    this is the code for the set exams function
    Code:
    /*
    	Sets the indicated exam to the score provided.
    	This over writes any score previously entered
    		without warning!!
    */
    void Student::setExamScore( int examNumber, double score )
    {
    	if( examNumber < 0 || examNumber > EXAM_LIMIT ) return;
    	exams[examNumber] = score;
    }
    
    /*

    this is the code for main

    Code:
    /*
      Jessie Brown
      cop2334
    
    
    
    
    
    
      */
    
    #include "Student.h"
    //Prototypes -- function declarations.
      //-----------------------------------
    
       void Menu_Selection();
       void enter_students (int,int& total);
       Student student[STUDENT_LIMIT];
       int find_student(int,int,int& total);
    
    
    
    int main()
    {
    
    
      Menu_Selection();
    
    
    
    
    
    
    
        // the following lines keep the console open
            cout << "\nPress <ENTER> to continue.\n";
            fflush(stdin);
            cin.get();
    
    
    	return 0;
    }
    
    
    /*------------------------------------------------------------------------------
            This section of code is the initial screen after employee signs in
                    to system.  From here said employee can choose what she must
                    do with each customer being assisted.
    ------------------------------------------------------------------------------*/
    
    
      void Menu_Selection()
    {
    
    
    
         int total=0, totalStudents =0,examNumber;
         double score;
         int studentID;
         int option;
         do
         {
              cout << endl
                   << "1. Add a new student to roster. \n \n"
                   << "2. Enter exam score for all students. \n \n"
                   << "3. Display student exam averages. \n \n"
                   << "4. Display course information for all students. \n \n"
                   << "5. Exit program: \n \n";
    
              cin >> option;
              cout << endl;
    
              switch (option)
               {
                    case 1:
                         enter_students (STUDENT_LIMIT,total);
                         cout << endl;
                         break;
    
                     case 2:
                          /* this allows you to enter an exam number and score for
                          each stutdent in this class.  assumes that you know the
                          number, that you have put the papers in some sort of order
                          that matches the order of students....if you skip a number
                          or the score does not track your average will be off as
                          a -1 will be put in that exam number spot.*/
                          totalStudents = total;
                            
                          for( int i = 0; i < totalStudents ; i++ )
                            {
                             int exams = -1;
                             cout << "Enter Exam number and score.\n";
                             cin >> examNumber; cin >> score;
                             exams = examNumber;
                             student[i].setExamScore(examNumber,score);
                             cout << student[i].getExamScore(exams) << endl;
                            }
    
                         break;
    
                    case 3:
                         /*this will find a particular student based on his ID number
                         and will then print the average of the scored he has taken
                         and that have been recorded, it will also list the test scores
                         individually so that one can see if there is one missing,
                         a missing one would be indicated by -1*/
    
    
                         int tempID;
                         cout << "Please enter the Student ID number\n";
                         cin >> tempID;
                          for( int i=0; i<EXAM_LIMIT; i++ )
    		          cout << student[tempID].getExamScore(i) << endl;
                              cout << "Avg = " << student[tempID].getExamAverage() << endl;
    
    
                         break;
    
                    case 4:
                         for( int i = 0; i < total ; i++ )
                            {
                             cout << student[i].getFullName() << endl;
                             cout << "ID: " << student[i].getID() << endl;
                             for(int j=0; j<EXAM_LIMIT; j++ )
                               {
    		             cout << student[i].getExamScore(j) << endl;
                               }
                             cout << "Avg = " << student[i].getExamAverage() << endl;
    
                            }
                         break;
                   case 5:
                        cout << "End of Program.\n";
                        break;
                    default:
                    cout << "Not a valid option. Please choose a valid option. \n\n";
               }
         }while (option != 5);
    
    
    }
    
    /*------------------------------------------------------------------------------
     This function allows a user to add student, assuming that each id number is
     original (like a social security number) id number is not checked for duplicity
     If class is full it will not allow you to register another student.
    ------------------------------------------------------------------------------*/
    void enter_students (const int STUDENT_LIMIT, int& total)
    {
     string temp1;
     string temp2;
    
     int tempID;
    
    
     if(total >= STUDENT_LIMIT)
           {
            cout <<"Registration closed for this section.\n";
           }
          else if(total <STUDENT_LIMIT)
            {
             cout <<"Please enter students first and last name.\n";
             cin >> temp1;
             cin >> temp2;
             student[total].setName(temp1,temp2);
    
             cout << "Enter student ID.\n";
             cin >> tempID;
             student[total].setID(tempID);
    
             cout <<  student[total].getFullName() <<endl;
             cout << "ID: " <<  student[total].getID() << endl;
    
    
    
             total++;
    
             }
    
     }
    please help thanks
    jessie

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    you have an array of exams per student
    but in the loop that sets the exam score you asking only one score per student

    as a result you can set for example
    exam 1 for 1st student
    exam 3 for 2nd
    exam 2 for 3rd

    I think you should modify this case to enter several scores for the same student
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21