The following code is not performing correctly. It opens the username file but does not display the mark.
#include <cstdlib> //these commands are pre processors directive
#include <fstream> //required for library function
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
cout << "Marking Program"<<endl;
string username;
cout << "Enter Students Username:";
cin >> username;
string filename = username + ".txt";
ifstream file(filename.c_str());
if (!file) {
cerr<<"Username not found"<<endl;
return EXIT_FAILURE;
string string1 ("DDRA");
string string2 ("DDRB");
string string3 ("0021");
string string4 ("CLR");
string string5 ("LDAA");
string string6 ("LDAB");
string string7 ("READ");
string string8 ("ABA");
string string9 ("STAA");
string string10 ("END");
int counter;
counter=0;
if (string1.find(filename.c_str()))
++counter;
if (string2.find(filename.c_str()))
++counter;
if (string3.find(filename.c_str()))
++counter;
if (string4.find(filename.c_str()))
++counter;
if (string5.find(filename.c_str()))
++counter;
if (string6.find(filename.c_str()))
++counter;
if (string7.find(filename.c_str()))
++counter;
if (string8.find(filename.c_str()))
++counter;
if (string9.find(filename.c_str()))
++counter;
if (string10.find(filename.c_str()))
++counter;
cout<< "students mark is"<<counter<<"out of 10"<<endl;
return EXIT_SUCCESS;
}
}
after the username is entered the message press any key appears but no mark is displayed