so basically i have four files named, "ASN, EXER,MID,FINAL" that have grades inputed in with the amount shown below.....all i want is to have them saved in an array so i can use them to calculate a grade....the code below is what i have right now, dont understand the errors, some help??

#include <fstream>
#include <iostream>
using namespace std;
 
int loadScores(double data[], int size, string fileName);
 
const int MAX_ASN = 11;
const int MAX_EXER = 12;
const int MAX_MID = 2;
const int MAX_FINAL = 2;
const string AREAS[] = {"Assignments", "Exercises", "Midterm", "Final Exam"};
const int INDEX_ASN = 0;
const int INDEX_EXER = 1;
const int INDEX_MID = 2;
const int INDEX_FINAL = 3;
 
 
 
int main() {
 
loadScores(double data[], int size, string fileName);
 
 
 
}
 
 
 
 
int loadScores(double data[], int size, string fileName) {
ifstream fin;
ofstream fout;
int data[MAX_ASN];
 
fin.open("asn.txt");
if (fin.fail()) {
cout << "Input file failed to open.\n";
exit(1);
}
 
 
int count = 0;
while(fin >> data[INDEX_ASN] && data[INDEX_ASN] < MAX_ASN) {
}
 
fin.open("exer.txt");
if (fin.fail()) {
cout << "Input file failed to open.\n";
exit(1);
}
 
 
int count = 0;
while(fin >> data[INDEX_EXER] && data[INDEX_EXER] < MAX_EXER) {
}
 
 
fin.open("mid.txt");
if (fin.fail()) {
cout << "Input file failed to open.\n";
exit(1);
}
 
 
int count = 0;
while(fin >> data[INDEX_MID] && data[INDEX_MID] < MAX_MID) {
}
 
fin.open("fin.txt");
if (fin.fail()) {
cout << "Input file failed to open.\n";
exit(1);
}
 
 
int count = 0;
while(fin >> data[INDEX_FINAL] && data[INDEX_FINAL] < MAX_FINAL) {
}
 
 
 
 
// Read the number of scores
// Also load scores into the data[]
int index = 0;
 
return index;
}

lastly....if your kind enough, can ya maybe post your aim or w/e wherein i can ask for your help a little quicker...dont really know if there are people out there that are that kind. but ya, thanks!

Dani AI

Generated

Two quick points before a suggested fix. is right that the immediate compile errors come from how the function is called in main and from incorrect variable declarations inside loadScores. The call in main looks like a prototype; you must pass an actual array or container, a size (if needed), and a filename. Inside loadScores the parameter is shadowed by a local array, count is redeclared multiple times, and the read loops try to read into a fixed index and compare that value to a max instead of advancing an index or pushing values into a container. Also be careful about types: use double for scores, not int, and open the filename passed into the function instead of hardcoding multiple files in one routine.

A safer, clearer approach is to write a small loader that reads all numbers from a single file into a std::vector<double> and returns how many were read. Call it once per file. This removes the shadowing, avoids manual index bugs, and makes error handling straightforward.

#include <fstream>
#include <iostream>
#include <vector>
#include <string>

int loadScores(const std::string& filename, std::vector<double>& out) {
    std::ifstream in(filename.c_str());
    if (!in) return -1;
    double value;
    while (in >> value) out.push_back(value);
    return static_cast<int>(out.size());
}

Practical tips: compile with warnings enabled (for example g++ -Wall -Wextra) to catch redeclarations and type issues; verify file contents (if the first number is a count, read it separately and then read exactly that many values); handle file paths and permissions; and keep one clear responsibility per function (one file => one load call). This approach will make the grade-calculation code much easier to write and debug.

You have at least two errors :
1) The function call.
2) Variable declartion.

The a look at this program.

/*    function prototype.
      For every call to print, the 
      compiler will check number
      of arguments, and thier data
      type.
*/
void print(const char buf[], int num); 
 
int main(void) 
{
/* declare the variables */
char msg[100]; 
int  i ; 
 
/* assign values to the variables */
strcpy(msg, "Hellow world");
i = 7;
/* call to function "print" */
print(msg, 5);
/* 
print(3.3); 
   This call will casue a compiler error
   since the function print should recive
   two arguments. first const char *.
   seconed of type int.
   The compiler knows it from the 
   function prototype.
*/
/*
declare the variable.
char  msg[100];
   This an error  
   because we already declared
   the variable msg */
return(0);
}
 
void print(const char buf[], int num)
{
cout << buf << "  " << num << endl;
cin.get();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.