0

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!

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by dude543
0

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();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.