two dimensional array

Hello, im working on a two dimensional array assignment. I need to get "scores" from a text file named: scores.txt from four students and calculate the averages.

i get this:
Please enter the scores file name:
scores
Please enter the average file name:
average
Press any key to continue . . .
Student Ave Quizzes
1-858993460.0 -858993460-858993460-858993460-858993460
2-858993460.0 -858993460-858993460-858993460-858993460
3-858993460.0 -858993460-858993460-858993460-858993460
4-858993460.0 -858993460-858993460-858993460-858993460
Quiz averages = -858993460.0-858993460.0-858993460.0-858993460.0
Press any key to continue . . .

obviously im doing something completely wrong!!!

any assistance please

This is my code

//Reads quiz scores for each student into the two-dimensional array grade (but
//the input code is not shown in this display). Computes the average score
//for each student and the average score for each quiz. Displays the quiz scores
//and the averages.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstdlib>
const int NUMBER_STUDENTS = 4, NUMBER_QUIZZES = 4;

void compute_st_ave(const int grade[][NUMBER_QUIZZES], double st_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of the indexed variables
//grade[st_num − 1, quiz_num − 1] contains the score for student st_num on quiz
//quiz_num.
//Postcondition: Each st_ave[st_num − 1] contains the average for student
//number stu_num.

void compute_quiz_ave(const int grade[][NUMBER_QUIZZES], double quiz_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES
//are the dimensions of the array grade. Each of the indexed variables
//grade[st_num − 1, quiz_num − 1] contains the score for student st_num on quiz
//quiz_num.
//Postcondition: Each quiz_ave[quiz_num − 1] contains the average for quiz number
//quiz_num.

void display(const int grade[][NUMBER_QUIZZES],
const double st_ave[], const double quiz_ave[]);
//Precondition: Global constants NUMBER_STUDENTS and NUMBER_QUIZZES are the
//dimensions of the array grade. Each of the indexed variables grade[st_num − 1,
//quiz_num − 1] contains the score for student st_num on quiz quiz_num. Each
//st_ave[st_num − 1] contains the average for student stu_num. Each
//quiz_ave[quiz_num − 1] contains the average for quiz number quiz_num.
//Postcondition: All the data in grade, st_ave, and quiz_ave has been output.

int main( )
{
using namespace std;
int grade[NUMBER_STUDENTS][NUMBER_QUIZZES];
double st_ave[NUMBER_STUDENTS];
double quiz_ave[NUMBER_QUIZZES];

char scores_name[16], average_name[16];
ifstream in_stream;
ofstream out_stream;

cout << "Please enter the scores file name: " <<endl;
cin >> scores_name;
cout << "Please enter the average file name: " <<endl;
cin >> average_name;

in_stream.open(scores_name);
out_stream.open(average_name);

in_stream.close();
out_stream.close();

system ("pause");

compute_st_ave(grade, st_ave);
compute_quiz_ave(grade, quiz_ave);
display(grade, st_ave, quiz_ave);
return 0;
}

void compute_st_ave(const int grade[][NUMBER_QUIZZES],double st_ave[])
{
for (int st_num = 1; st_num <= NUMBER_QUIZZES; st_num++)
{//Process one st_num:
double sum = 0;
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
sum = sum + grade[st_num - 1][quiz_num - 1];
st_ave[st_num - 1] = sum/NUMBER_QUIZZES;
}
}


void compute_quiz_ave(const int grade[][NUMBER_QUIZZES],double quiz_ave[])
{
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
{
double sum = 0;
for(int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++)
sum = sum + grade[st_num - 1][quiz_num - 1];
quiz_ave[quiz_num - 1] = sum/NUMBER_STUDENTS;
}
}


void display(const int grade[][NUMBER_QUIZZES],
const double st_ave[], const double quiz_ave[])
{
using namespace std;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
cout << setw(10) << "Student"
<< setw(5) << "Ave"
<< setw(15) << "Quizzes" <<endl;
for (int st_num = 1; st_num <= NUMBER_STUDENTS; st_num++)
{
cout << setw(10) << st_num
<< setw(5) << st_ave[st_num - 1] <<" ";
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
cout << setw(5) << grade[st_num - 1][quiz_num - 1];
cout << endl;
}

cout << "Quiz averages = ";
for (int quiz_num = 1; quiz_num <= NUMBER_QUIZZES; quiz_num++)
cout << setw(5) << quiz_ave[quiz_num - 1];
cout << endl;

system ("pause");

}
1. Put your code in [code][/code] tags or else it's a pain to read.

2.
I need to get "scores" from a text file named: scores.txt
So why are you entering "scores" instead of "scores.txt"?

3.
1
2
3
4
5
in_stream.open(scores_name);
out_stream.open(average_name);

in_stream.close();
out_stream.close();

So you open the files, then close them without doing anything. Don't you need to read data from them in order to fill your arrays?

Not going to look through more until you fix #1.
Topic archived. No new replies allowed.