So I have a couple of problems with this assignment and I need a bit of help. The first is Went ever I input the name of a college or university that I know is on the list, it causes an infinite loop and repeats the menu forever. This will only happen if I type the name of a college or university(I could type giberrish and it wouldn't cause an infinite loop to occur). The last problem is how do I stop the program from displaying the two statements such as the "This institution is/isn't the list. I only want the program to display one of these statements whenever the user inputs the name of a college/university; not the whole entire list.
Note1: I need to mention that this menu has to have a vector of strings and array read from a file an into seperate functions.
Note2: If you're wondering why there are empty if/else statements, it's because I'm trying to fix this problem before I advance.
Note3: I've posted 2 txt files for you look to at.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;
void collegesUniversities()
{
ifstream campuses;
campuses.open("colleges.txt");
vector<string> schoolVector;
string schools;
cout << "\nEnter the name of your college/university. ";
cin >> schools;
if(!campuses)
cerr << "Error opening file. ";
else
{
while(getline(campuses,schools, '\n'))
{
schoolVector.push_back(schools);
}
}
for(size_t i=0; i < schoolVector.size(); i++)
{
cout << schoolVector.at(i) << '\n';
if(schools != schoolVector[i])
cout << "\nThis institution is on the list. ";
else
cout << "\nThis institution isn't on the list. ";
}
campuses.close();
}
int main()
{
int choice;
cout << "Welcome to my college and university search program.\n";
cout << "\nPress any button to continue.\n ";
system("pause>nul");
do
{
cout << "\nPress 1 to enter possible colleges and universities.";
cout << "\nPress 2 to find out how many colleges and universities";
cout << " appear in your state.\n";
cout << "Press 3 to find the total amount of colleges and";
cout << " universities in our list. ";
cout << "\nPress 4 to quit. ";
cin >> choice;
if(choice == 1)
{
collegesUniversities();
}
else if(choice == 2)
{
}
else if(choice == 3)
{
}
else if(choice == 4)
{
cout << "\nThank you for using my program. ";
cout << "Have a great day.\n ";
}
else
{
cerr << "\nError, Invalid input. ";
cout << "Only integers from 1 through 4 are allowed.\n";
}
}
while(choice != 4);
}