Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2018
    Thanked 0 Times in 0 Posts

    c++ question getting average

    Here is my code. I am trying to add a way to get the overall average grade for each student. I am using just class student and using both getdata and putdata. Thoughts anyone?

    #include <iostream>
    #include <conio.h>
    #include <math.h>
    using namespace std;
    class students
        int id;
        char name[20];
        int subject_1;
        int subject_2;
        int subject_3;
        void getdata()
            cout << "\n Enter id: ";
            cin >> id;
            cout << "\n Enter name: ";
            cin >> name;
            cout << "\n Enter grades in Subject 1: ";
            cin >> subject_1;
            cout << "\n Enter grades in Subject 2: ";
            cin >> subject_2;
            cout << "\n Enter grades in Subject 3: ";
            cin >> subject_3;
        void putdata()
            cout << "\n" << id << "\t" << name << "\t" << subject_1 << "\t" << subject_2 << "\t" << subject_3;
    int main()
      students s[20];
      int i, n;
      cout << "\n Enter number of students: ";
      cin >> n;
      for(i=0; i<n;i++)
      for(i=0; i<n;i++)
      return 0;
    Last edited by vinyl-junkie; Dec 31st, 2018 at 06:12 AM. Reason: added code tags

  2. #2
    New Coder
    Join Date
    May 2006
    Thanked 0 Times in 0 Posts
    I am not clear on what you are asking.

    Are you just looking for confirmation that what you have so far is okay?
    I see that you take in the names and subjects, and output them.
    But I don't see where you compute the average grades. That should be simple enough: (subject_1 + subject_2 + subject_3) / 3
    Is that what you are asking about?


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts