I have made the following code here that will read the test scores from this input file here.
Please be aware that more tests scores will be entered thus me not finding the exact size of the array. The total number of tests would be less then 50 though. Now that was the input here, the output after constructing my code. I got this here
May anyone please tell me what i'm doing wrong. I would highly appreciate it. Thank you for taking your time to read this
void studenttestreader (int testscores,int size,ofstream &out, ifstream&in)
//Total number of students not defined. There would be less then 50 though. So have numberofstudents declared to 0;
//while file is open
while (in>>testscores[numberofstudents] && numberofstudents<size)
Aslo, there is a similar post like this, so please ignore that. I tried deleting it, but realized I couldn't really on this forum.
nStudents = 0 ;
while ( extraction from input stream for student is successful and nStudents is less than size )
extract info for student from input stream
write student to output stream
How many times should you extract information from the input stream for one student?
For one student, I should extract information only once...I did a similar approach a couple of days ago and it worked like this too, but i'm just totally lost how to do those while loops when reading files :(
I was using this approach from another assignments problem; however im aware im wrong but don't know how. would like to know what the problem is :(
Edit: meaning to say that I was using this approach from this following code which works.
1 2 3 4 5 6 7 8 9 10
void ReadStudentid_TestAnswers(ifstream &infile, ofstream& outfile,char studentid, int idsize,char answers,int answersize)
//Read data into infile
Cire,mince you said that, why exactly does it ignore every other record?
You read one record in in the loop condition. You don't do anything with that record (iow, you ignore it.) You immediately overwrite it by reading in the next record inside the loop body. This happens for every iteration of the loop.
Perhaps your actual code differs from your reproduction.
I was looking and researching over the internet and they all seem to be using this example. Not saying your wrong. I'm pretty sure your right aince your more expierenced them me. Meanwhile, if this does ignore every other record, then what can I do not to ignore it?
Also,while(infile>>studentid>>answers) when I enter in a data for instance
. Does this input start from "while(infile>>......) or underneath the while part of code.