The code below hopefully might clear some things up...
Expand|Select|Wrap|Line Numbers
- struct listInfo //struct containting state information
- {
- char name [15];
- int population;
- int area;
- int year;
- int order;
- char capital[15];
- char abbrev[3];
- };
- void reportYrPop (SortedType <listInfo>& list, int density, ostream& output)
- {
- listInfo getYrPop;
- string input;
- bool found;
- cout <<"Type in state to find year of admission and population: ";
- getline (cin, input); //get the state I want to look for in the list
- getYrPop.name = input; //I know this is wrong code. But I want to put the user input (string) into a struct variable (char), so when I call retrieveItem later on below, it'll retieve the correct information from the linked list corrposding with the state that was just inputted by the user.
- while (!input.empty()) //while user doesn't type an empty string
- {
- list.RetrieveItem(getYrPop,found); //Searches for an item, with all state information, from the list. Passes an object and a bool variable as parameters.
- if (found) // if the state is in the list
- {
- cout << "Year and Population Density: "<< getYrPop.year << " " << density<<endl; //prints to screen
- output <<"Year and Population Density: "<< getYrPop.year << " "<<density<<endl; //prints to file
- }
- else //if the state was not found
- {
- cout <<"The state was not found"<<endl;
- output << "The state was not found"<<endl;
- }
- cout <<"Type in state to find year of admission and population: ";
- getline(cin,input); //keep getting user input until user enters an empty string
- }
- }