on line 28 and 29 i do not understand the errors i am getting
i am taking first and last names from a file and 10 grades and then finding the average and then outputting it to the window. no sorting or anything complicated but i do not why i get that error and what i can do to fix it
Here is my program
main.cpp:28: error: conversion from 'std::string*' to non-scalar type 'std::string' requested main.cpp:29: error: conversion from 'std::string*' to non-scalar type 'std::string' requested
i am taking first and last names from a file and 10 grades and then finding the average and then outputting it to the window. no sorting or anything complicated but i do not why i get that error and what i can do to fix it
Here is my program
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
const int NUM_GRADES=10; ////Total grades
const int NUM_STUDENTS=10; //Total Number of Students
void gData(string firstName[], string lastName[], int grades [][NUM_GRADES]); //Function to read from input file.
void CompAvg(string firstName, string lastName, int grades [][NUM_GRADES], float avgs []); //calculate average of each student.
void printData(string firstName, string lastName, int grades [][NUM_GRADES], float avgs []); //Function to display the result.
int main()
{
//string names [NUM_STUDENTS];
string firstName[NUM_STUDENTS], lastName[NUM_STUDENTS];
int grades [NUM_STUDENTS][NUM_GRADES];
float avgs [NUM_STUDENTS];
//Calling functions
gData(firstName, lastName,grades);
CompAvg(firstName, lastName, grades, avgs);
printData(firstName, lastName, grades, avgs);
return 0;
}
void gData(string firstName [],string lastName [], int grades [][NUM_GRADES])//(string names, int grades)
{
string filename;
ifstream fin;
cout<<"Enter filename: "; //User required to enter file name
cin>>filename;
fin.open (filename.c_str());
while(!fin) {
cerr<<"Error: Please enter a valid file name.\n";
cout << "Enter filename: ";
cin >> filename;
fin.open (filename.c_str());
}
for (int i=0;i <= NUM_STUDENTS; ++i)
{
fin >> firstName[i] >> lastName[i];
for (int j=0;j<=NUM_GRADES; ++j)
{
fin >> grades [i][j];
}
}
fin.close();
}
void CompAvg(string firstName [], string lastName [], int grades [][NUM_GRADES], float avgs [])//(int grades, float average)
{
float total = 0; //To hold an average temporarily
ifstream fin;
for(int i=0;i<NUM_GRADES; ++i)
{
fin >> firstName[i] >> lastName[i];
for(int j=0;j<NUM_GRADES; ++j)
{
fin >> grades [i][j];
total += grades[i][j]; //Adding up all the grades
}
avgs [i] = total /NUM_GRADES;
}
}
void printData(string firstName[], string lastName[], int grades[][NUM_GRADES], float avgs[])
{
// output table
cout<<"Name\t\t\t\t\t\t"<<"Grades\t\t\t\t\t"<<"Average\n\n";
for(int i=0;i<NUM_STUDENTS;++i)
{
cout<<firstName[i] << lastName[i];//Display name
for(int j=0;j<NUM_GRADES;++j)
{
cout<<grades[i][j]; //Display 10 grades
}
//cout<<fixed<<setprecision(2)<<"\t"<<names[i]<<"\n"; //Display Grades
}
}