I have this lab that's got me stumped. The assignment reads
Write programs for the following and test to make sure they work. Please follow the book’s guidelines or my style guidelines to write code. Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade.. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of 20 components of type StudentType. Your program must contain at least the following functions: 1. A function to read the students’ data into an array. 2. A function to assign the relevant grade to each student. Your program should output each student’s name in this form: last name followed by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.
This is my code thus far. It only indicates one person and the list has four.
the list is scores.txt and reads
Miller Andrew 98
Hooks Tony 87
Meso Alex 78
Smith Jing 88
@TarikNeaj I might misinterpret which line you were referring to in your post. If you were referring to line 82, then yes, it is wrong and solution in your second post is correct.
No errors after changing the one line to StuRead(inFile, students); but my output file is empty. Thanks TarikNeaj and MiiNiPaa
My code looks like this and I'm looking at the Youtube Video.
void StuRead(ifstream& indata, studentType students[])
{
for (int x = 1 0; x < 20; ++x) {
ifstream inFile; //Create new file stream not associated with anything
inFile indata >> students[x].studentLName //Read data from invalid stream, read fails and nothing is written
>> students[x].studentFName
>> students[x].testscore;
}
}