These are the instructions for the project. I can't deviate from this, the professor has a thing about us changing things.
"Collect an athlete's performance scores and calculate the final score using an array and input file.
Program Requirements:
* Allow the user to enter the name of the input file
* Use an assert statement or an if statement to check for a valid input file
* Store the scores in an array
* Use functions and incorporate value, reference and constant reference parameters appropriately."
This is all I can come up with:
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
|
#include <iostream>
#include <fstream>
#include <cassert>
#include <string>
using namespace std;
void openfile(ifstream& infilename);
void getscores(double scores[15], ifstream& infile);
//Call all functions and display data.
int main()
{
ifstream infile;
double scores[15];
openfile(infile);
getscores(scores, infile);
system("pause");
return 0;
}
//Locate and open the input file.
void openfile(ifstream& infile)
{
string infilename;
cout << "Enter the name of the input file: ";
cin >> infilename;
infile.open(infilename);
assert(infile);
}
//Get scores from user, store in file
void getscores(double scores[15], ifstream& infile)
{
int i;
do
{
cout << "Enter a performance score: ";
infile >> scores[i];
}
while (i <= 14);
}
|
It fails to locate the input file (TextFile1.txt), so I can't test the rest of the program since that first step is failing.
AND now it's suddenly giving me a bunch of other error messages and failing to start even though it at least ran the first step before, and I didn't touch the code.