Array / Pass by reference question

I am having problem figuring what my next step should be concerning this program I am writing. I am trying to write a program that using "pass by reference" to calculate the average grade for 6 students, and display in this format: Student name -ID, Average and Letter Grade. Now, my problem is how do i create a program that will do this for 6 students (multiple arrays) and how do I write the if statement to display grade each time or is there another or easier way of doing it. I am very new to progamming.....
Here is what I have so far....It works but for only one student at a time and I know its wrong.

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;

struct StuRec
{
int id;
int scores [4]; // built in array
double avg;

};// terminate


// pass by reference
void CalcAverage (StuRec& S);

void main ()
{
char stuname[20];


// populate the StudentName using a keyboardcout
cout<<"Enter A Name:";
gets_s(stuname);
cout<< stuname;
cout<<endl;

// declare and allocate variables
StuRec r;

// how to allocate numbers in the record? eg. enter student id

cout<<"Enter ID;";
cin>>r.id;
cout<<r.id;
cout<<endl;


// populate the scores using a keyboard
cout<<"Enter 4 scores: ";
for(int i=0; i<4; i++) // populating the student record r
cin>>r.scores[i];



// calculate average using
CalcAverage ( r );// next step is to make a prototype


cout<<"Average Score: "<<r.avg<<endl;

//if statement

if (r.avg >=90)
cout<<" A: ";
if (r.avg >=80 && r.avg <90)
cout<<"B:";
if (r.avg >=70 && r.avg <80)
cout<<"C:";
if (r.avg >=60 && r.avg <70)
cout<<"D:";
if (r.avg <60)
cout<<"F:";

// Display
cout<< fixed << setprecision(6);
cout<<"Student Name:"<<setw(8)<<stuname<<" ID: "<<setw(8)<<r.id<<"Score: "<<setw(8)<<r.avg<<endl;


}//main

void CalcAverage ( StuRec& S)
{

int sum = 0;
for (int i=0; i<4; i++)
sum+= S.scores[i];

S.avg = static_cast<double>(sum)/4;

}


any help will be highly appreciated.
Thanks
Well one idea is to have one single array of student objects where each instance represents a single student record. Make the student record type a class and define an interface for setting the values. Also you can overload operator<< to print each instance of the class.

You could pick at this article for some examples on how to do this with object oriented design. Compile it and use the debugger to study it and perhaps it'll give you some ideas.
http://cplusplus.com/forum/articles/10879/
dont post multiple times please.. you have got reply to your other post.
Topic archived. No new replies allowed.