0

Hi. I'm David a newbie. I have just started Classes in C++ and I'm doing a GPA Calculator program. I have most of the program working but the average calculator seems to be giving me trouble. Please help. This is open to constructive criticism. All inputs will be gladly appreciated. Thank you in advance.

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class GpaCalculator
    {
        public:


    void displayMessage ()
    {
        char  gradeLetter [4] = {};
        string courseName [4] = {""};

    for ( int x = 0; x < 4; x++ )

         {

             cout<< "Please enter name of course:";
             getline(cin, courseName [x]);


             for ( int y = 0; y < 4; y++ )

                 {
                     cout<< "Enter grade recieved:";
                     cin>> gradeLetter [y];
                     break;

                 }
                    cin.ignore (100, '\n');
         }

         system("cls");
         for ( int x = 0; x < 4; x++ )

            {

              for ( int y = 0; y < 4; y++ )

               {
                 cout<< courseName[x]<< right<< setw (7)<< gradeLetter[y]<< '\n'<<'\n';
                 break;
               }

            }
    }

double getAverage ()

 {
  char letter [4] = {'a', 'b', 'c', 'd'};
  char  gradeLetter [4] = {'a', 'b', 'c', 'd'};
  double average = 0.0;

     for ( int y = 0; y < 4; y++ )
      {

       if  (gradeLetter [y] == 'a')
           {
           gradeLetter [y] = 4;
           }


        else
        if (gradeLetter [y] == letter[1])
            {
            gradeLetter [y] = 3;
            }

          else
          if (gradeLetter [y] == letter[2])
              {
              gradeLetter [y] = 2;
              }

          else
          if (gradeLetter [y] == letter[3])
              {
              gradeLetter [y] = 1;
              }
    }

       average = ( gradeLetter [0] + gradeLetter [1] + gradeLetter [2] + gradeLetter [3] ) / 4;
       return average;

 }


        private:

        double average;
        string courseName [4];
        char  gradeLetter [4];
        char letter [4];
};



int main()
{

    GpaCalculator cal;

    cal.displayMessage ();


    cout<< "Your GPA is:"<< cal.getAverage ();
return 0;

}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Comatose
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.