Hi again everybody,
I am having a bit of trouble in getting this script to work properly. Two error messages are coming up when I compile this code. They are as follow:
1) Error 1 error C2664: 'fillArray' : cannot convert parameter 3 from 'int [50]' to 'int &' f:\My Documents\Visual Studio 2005\Projects\Final Using Arrays\Final Using Arrays\Final Using arrays.cpp 49
2) Error 2 error C2440: '=' : cannot convert from 'std::string' to 'char' f:\My Documents\Visual Studio 2005\Projects\Final Using Arrays\Final Using Arrays\Final Using arrays.cpp 168
The problem is occurring when I am trying to store a name (which is gotten inside of the function "fillArray", inside of an Array which is located inside ofthe main function. I am sure it is a coding error (it usually is with me) and I really appreciate the help, this is only my first semester of study in the C++ language. Anyway here is the code. The Error are on line 49 and 168 Respectively. (They are labeled)
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void calculateAverage(int test1,int test2,int test3,int test4,int test5, int& student_average);
char calculateGrade(int& student_average);
int student_counter(ifstream& input2, int& student_count);
void fillArray (ifstream& input3, int student_count, int& grades, int& student_name);
int main()
{
string studentName;
int test1,test2,test3,test4,test5;
char grade = ' ';
int student_average = 0;
int student_count = 0;
double class_average = 0;
int class_total = 0;
int grades[50];
string student_name[10];
int counter;
ifstream infile;//input file stream variable
ifstream infile2;
ofstream outfile; //output file stream variable
infile.open("studentgrades.txt"); //open input file
infile2.open("studentgrades2.txt"); //open input file
outfile.open("results.out"); //open output file
//Print the Heading of the output file!
outfile << "Student" << setw(15) << "Test1" << setw(10) << "Test2" << setw(10) <<
"Test 3" << setw(10) << "Test 4" << setw(10) << "Test 5" << setw(10) <<
"Average" << setw(10) << "Grade" << setw(10) << endl;
student_counter(infile2,student_count);
cout << student_count << endl;
fillArray (infile, student_count, grades, student_name); //line 49
cout << student_name[0] << endl;
//While there is still data to be read in the input file do the following:
//for (counter = 0; counter <= student_count; counter++)
//{
//infile >> studentName >> test1 >> test2 >> test3 >> test4 >> test5;
//calculateAverage(test1,test2,test3,test4,test5,student_average);
//if (studentName == "end")
//{
// break;
//}
//output the information to the output file
//outfile << setw(6) << studentName << setw(15) << test1 << setw(10) << test2 << setw(10) <<
// test3 << setw(10) << test4 << setw(10) << test5 << setw(10) <<
// student_average << setw(10) << calculateGrade(student_average) << setw(10) << endl;
//class_total = class_total + student_average;
//}
//class_average = class_total/student_count;
//Print Final stats to the output file
//outfile << endl;
//outfile << setw(20) << "Total Number of Students = " << student_count <<
//setw(20) << "Class Average = " << class_average << endl;
infile.close();
outfile.close();
return 0;
}
int student_counter(ifstream& input2, int& student_count)
{
string studentName;
int test1,test2,test3,test4,test5;
//While there is still data to be read in the input file do the following:
while (input2)
{
input2 >> studentName >> test1 >> test2 >> test3 >> test4 >> test5;
if (studentName == "end")
{
return student_count;
}
student_count++;
}
}
void calculateAverage(int test1,int test2,int test3,int test4,int test5, int& student_average)
{
student_average = ((test1+test2+test3+test4+test5))/5;
}
char calculateGrade(int& student_average)
{
char grade;
switch((student_average) / 10)
{
case 10:
case 9:
grade = 'a';
return grade;
case 8:
grade = 'b';
return grade;
case 7:
grade = 'c';
return grade;
case 6:
grade = 'd';
return grade;
default:
grade = 'f';
return grade;
}
}
void fillArray (ifstream& input3, int student_count, int& grades, string& student_name)
{
string studentName;
int test1,test2,test3,test4,test5;
int counter = 0;
int name_counter = 0;
int grade_counter = 0;
int name_number = 0;
//While there is still data to be read in the input file do the following:
for (counter = 0; counter <= student_count; counter++)
{
input3 >> studentName >> test1 >> test2 >> test3 >> test4 >> test5;
for (name_counter = 0; name_counter < 1; name_counter++)
{
name_number++;
student_name[name_number] = studentName ; // line 168
}
if (studentName == "end")
{
break;
}
}
}