Hello everyone, I'm having some trouble with a program with this description:
Write a program that prompts the user to enter a name, searches a file (teacherlist.txt) for that name, and outputs to the screen the teacher’s name and room number. .
Note that I already have a huge text file filled with names and room numbers. If you would like to see it, i will be glad to show you.
Basically, i have some code down, though for the most part I am lost. If anyone could guide me a bit, i would truly appreciate.... im not sure how to go about this at a....
*This is what i have so far...
Code:#include <iostream> #include <iomanip> #include <fstream> #include <cstring> #include <math.h> void main() { ifstream in_file; int a, name_length, count; string find_teacher; char list; // Opens the teacherlist.txt file in_file.open("teacherlist.txt"); cout << "Enter in the teacher's last name to obtain room information" << endl; cin >> find_teacher; name_length = find_teacher.length(); getline(in_file, list); /* for(int i=0; i<name_length; i++) { cout << find_teacher[i] << endl; } */ // Sets All array slots to 0 a=0; /* Sets Count to zero so it can be used to find whether or not i have found the name or not */ count=0; while(!in_file.eof()) { while(list!=',') { if(list[a]==find_teacher[a]) { a++; count++; } if(list[a]!=find_teacher[a]) { // Since it found a letter that doesn't match, it tries a new line // The file marker does not go back to the beginning of the File getline(in_file, list); a=0; count=0; } } } }
Any help would be great... THank you all in advance for even reading such a post.



LinkBack URL
About LinkBacks


