I was trying to create a simple struct array database that would be able to look up a user id and print out there first name, last name and age. So I've created a text file with 10 simple names ...here is my code ...can any one help me with this ...
//my code
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct namesOfTen
{
string fName;
string lName;
int age;
int id;
} tenNamesId[10];
void seqOrderedSearch (const namesOfTen& list, int searchItem);
int _tmain(int argc, _TCHAR* argv[])
{
ifstream inFile;
ofstream outFile;
inFile.open("C:\\Comp220\\names_10_ch11.txt");\\this is where my text file is located
if(!inFile)
{
cout << "input file not found\n\n";
return 1;
}
for (int i=0; i < 10; i++)
{
inFile >> tenNamesId[i].fName;
inFile >> tenNamesId[i].lName;
inFile >> tenNamesId[i].age;
inFile >> tenNamesId[i].id;
}
inFile.close();
cout<<"Please enter user ID"<<endl;
cin>>tenNamesId[2].id;
return 0;
}
int seqOrderedSearch (const namesOfTen& list, int searchItem)
{
int loc;
bool found = false;
for (loc = 0; loc < tenNamesId.id ; loc++)
if (list.id[loc] == searchItem)
{
found = true;
break;
}
if (found)
return
cout<<"First Name:"<<tenNamesId.fName<<"Last Name:"<<tenNamesId.lName
<<"Age:"<<tenNamesId.age<<endl;
else
return -1;
}