Please Help! not sure why these errors are occurring

This is a discussion on Please Help! not sure why these errors are occurring within the C++ Programming forums, part of the General Programming Boards category; Hi again everybody, I am having a bit of trouble in getting this script to work properly. Two error messages ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Please Help! not sure why these errors are occurring

    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;
    }
    
    
    }
    
    
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,068
    On line 49, grade isn't an integer, it's the name of an array, which is more like a pointer. If you want to pass an integer, you have to provide an index, if you want to pass the array. Change your function parameter from int& to int [].

    As for 168, since you're passing a reference to the array, rather than passing the full array, you now have a single string in the function, when you use indexes on that string you're now refering to a single character in the string. Again, you're gonna want to change your string& to string [].
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Thanks, will try!

    Thank you so much for the advice, and I really do appreciate the help. I will let you know how it turns out!


    Thanks,
    Jeff Gross

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21