Need help fixing program...

I am getting the following error:
------------------------------------------
assignment10.cpp:24:13: warning: multi-character character constant
[-Wmultichar]
getData('grades.txt', Names, scores, averageScores, &count);
^
assignment10.cpp:24:13: warning: character constant too long for its type
assignment10.cpp:24:5: error: no matching function for call to 'getData'
getData('grades.txt', Names, scores, averageScores, &count);
^~~~~~~
assignment10.cpp:14:7: note: candidate function not viable: no known conversion
from 'int' to 'char *' for 1st argument
void getData(char fileName[], string names[], double arr[][5], d...


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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
	#include <cmath>
	#include <string>
	#include <iomanip>
	#include <fstream>
	#include <cstring>

	using namespace std;
	const int numrows=10;
	const int numcol=5;

	int maxIndex(double arr[], int size);
	double calculateAverage(double arr[], int size);
	void getData(char fileName[], string names[], double arr[][5], double avg[] , int *size);
	void print(string Names[], double scores[][5], double avg[], int size);

	int main()
	{
	   int count = 0;
	   string Names[numrows];
	   double scores[numrows][numcol];
	   double averageScores[numrows];
	   //compute score and grades
	   getData("grades.txt", Names, scores, averageScores, &count);
	   //Outputs final results
	   print(Names, scores, averageScores, count);

	   //calculateAverages(averageScores, classAverage, numrows);


	   return 0;
	}

	int maxIndex(double arr[], int size){
	   int max = 0;
	   for(int i = 1; i < size; i++){
	       if(arr[i] > arr[max]) max = i;
	   }
	   return max;
	}

	double calculateAverage(double arr[], int size){
	   double avg = 0;
	   for(int i = 0; i < size; i++){
	       avg += arr[i];
	   }
	   avg /= size;
	   return avg;
	}

	void getData(char fileName[], string names[], double arr[][5], double avg[], int *size){
	   *size = 0;
	   ifstream inFile(fileName);
	   while(inFile >> names[*size]){
	       double x = 0;
	       for(int j = 0; j < 5; j++){
	           inFile >> arr[*size][j];
	           x += arr[*size][j];
	       }
	       avg[*size] = x / 5.0;
	       (*size)++;
	   }
	}

	void print(string Names[], double scores[][5], double avg[], int size){
	   cout << fixed << setprecision(2);
	   cout << "Name\tTest 1\tTest 2\tTest 3\tTest 4\tTest 5\tAverage\n";
	   for(int i = 0; i < size; i++){
	       cout << Names[i] << "\t";
	       for(int j = 0; j < 5; j++){
	           cout << scores[i][j] << "\t";
	       }
	       cout << calculateAverage(scores[i], 5) << "\n";
	   }
	   cout << "Class average: " << calculateAverage(avg, size) << "\n";
	   cout << "Student with highest grade: " << Names[maxIndex(avg, size)] << "\n";
	}
i could be wrong, but it doesnt look like you opened the file for grades.txt. try opening it before you use it with
ifstream("grades.txt");
before line 24.
and make sure you close it after youre finished using it.
Please to not post partial or complete solutions to homework assignments. Such submissions are a violation of the academic honesty policy in the syllabus. Email your professor or stop by his office if you have any questions on class assignments.
Last edited on
closed account (48T7M4Gy)
Impersonating or otherwise a professor and claiming to know another person under these alleged circumstances could have disastrous consequences for you and particularly the health and welfare of a student, alleged DrHayes. You are probably in breach of your duty of care, negligent for misusing the power imbalance inherent in your alleged position. I will be watching with close interest and suggest you tread very warily in any further steps you decide to take.
closed account (48T7M4Gy)
Thanks for the report. DrHayes is up for worse than a pink slip.
Topic archived. No new replies allowed.