Someone please help me I'm having my exam tmrw! So nervous!!
Im having trouble combining both the .txt files in to 1 file and run the program which I have coded.
The output is what I wanted but it goes:
James
90
Thomas
50
Sheila
60
Jessica
20
Precillia
10
2 out of 5 of the class has failed the test.
I want the output of this program to be like:
James 90
Thomas 50
Sheila 60
Jessica 20
Precillia 10
2 out of 5 of the class has failed the test.
---
I've attached the necessary files. here is my program;
Code:#include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { string getcontent; ifstream openfile ("names.txt") ; if (openfile.is_open()) { while(! openfile.eof()) { openfile >> getcontent; cout << getcontent << endl; } } int marks[100]; int x=0,fail=0, pass=0; fstream textfile; textfile.open("marks.txt"); while(! textfile.eof()){ textfile >> marks [x]; if(marks[x]<50){ fail++; } else{ pass++; } x++; } textfile.close(); openfile.close(); cout << fail << " students out of "<< (fail+pass) << " did not pass."; return 0; }
Attachment 11410Attachment 11411Attachment 11412