I'm about ready to pull my hair out. Honestly, I'm not even sure where my error is. It's matching up code samples I've seen from the web as well as my textbook. And I'm 100% lost
Here's the requirement. I'm supposed to create a 300 space array, then read a data file into it. Then I'm supposed to enter in an ID number and search the array for it.
Here's the thing. When I first wrote the code and got it to compile, I typed in the 1st number from the data file (just to see if my worked) and for some strange reason, it came up not found. So I added a line to write to the screen all the things that were put in the array. Strangely enough the 1st 5 entries didn't show up at all, neither did the last one. I checked the data file, and there's 301 entries instead of 300 (the prof said there was 300 entries) but I don't know if that causes issues.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{ //start of the main program section
int input, arrcount=0;
int idarray[300];
bool flag=false;
ifstream idfile;
idfile.open ("Data_IDN_300.txt");
while (!idfile.eof() ) // do it until reaching the END OF FILE
{//Start of the while loop to get the data from the file
for (arrcount=0; arrcount<300; ++arrcount)
{// fill the array with data from the file
idfile >> idarray[arrcount];
cout << idarray[arrcount] <<endl;
}//End filling the Data from the file
}//end of the while Not end of file loop
cout<<"=======Section 1 Started========="<<endl;
cout <<endl;
cout<<"Enter ID Number:"<<endl;
cin>>input;
for (int arrcount=0; arrcount<300; arrcount++)
{//Starting to loop the array to search for a value
if (idarray[arrcount]==input)
{//checking the array to see if the value you entered is there
flag=true;
break;
}//ending the loop to see if there value is there
}//ending the search array for a value
idfile.close();
if (flag==true)
cout<<"Access Granted"<<endl;
else
cout<<"Access Denied"<<endl;
cout<<"Section 1 Completed"<<endl;
system ("pause");
system ("cls");
return 0;
} //end of the main program
I hate to but everyone, but my text and my google fu are failing me