can someone help? Function Prototype with array

I am just learning c++ and, I am trying to create a function out of the lines that are surrounded by stars. I am at my wits end! Does anyone have a suggestion or reference that might help me figure this out.

Here is my code:

int a, b, c, x, y, z; // global variables

double examGrades[100]; // arrays


int getStudentNumber(int studentNumber); // prototypes


int main () // main program
{
z = getStudentNumber(z); // fn - input student qty.
cout << endl;

**************************************************************************

cout << "Enter the EXAM grades for this class: " << endl;

for (y=0; y<=z; y++)
{
cin >> examGrades[y];
}

******************************************************************************

cin.ignore(2);
return 0;
}

int getStudentNumber(int studentNumber)
{
int students = 1;
cout << "Enter the number of students in the class: "<<endl;
cin >> students;
students = students - 1;
return students;
}
You mean something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
 void GetExam();

...

void GetExam()
{
  cout << "Enter the EXAM grades for this class: " << endl;

  for (y=0; y<=z; y++)
  {
    cin >> examGrades[y];
  }
}
Thanks for the reply! I am unable to use void as:

cin >> examGrades[y];

is in the function.

Here is something I tried that did not work, Any help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>			
#include <cmath>	
#include <iomanip>
#include <stdio.h>
#include <ctype.h>
#include <fstream>

using namespace std;

int a, b, c, x, y, z;                         // global variables

double examGrades[100];


int getStudentNumber(int studentNumber);      // prototypes
int getExamGrades(int eGrades, int sNum);


int main ()                                   // main program
{
		z = getStudentNumber(z);              // fn - input student qty.
		cout << endl;	
        getExamGrades();	
		examGrades[] = getExamGrades();

	    cin.ignore(2);
		return 0;
}

int getStudentNumber(int studentNumber)
{    
    int students = 1;
	cout << "Enter the number of students in the class: "<<endl;
	cin >> students;
	students = students - 1;
	return students;
}

int getExamGrades(int eGrades, int sNum)
{
    cout << "Enter the EXAM grades for this class: " << endl;
    for (y=0; y<=z; y++)
    {
    cin >> examGrades[y];
    }	
}


This code fails miserably :(
What has this cin >> examGrades[y]; to do with being unable to use void?

You don't need parameters for that function since you don't use them. On the other hand using global variables are not really good
cool i like your name coder777.

777 = God Jesus christ
Topic archived. No new replies allowed.