#include <iostream>
#include <string>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
staticbool truth = true;
void looping(vector<string> plates, int numPlates);
int main(int argc, constchar * argv[])
{
int numPlates;
string input;
cout << "How many plates are there? ";
cin >> numPlates;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
vector<string> plates(numPlates);
for (int i = 0; i < numPlates; i++)
{
cout << "Enter plate " << i+1 << ": ";
getline(cin, input);
plates[i] = input;
}
looping(plates, numPlates);
if (truth == false)
{
cout << "The door cannot be opened!" << endl;
}
else
{
cout << "The door can be opened!" << endl;
}
return 0;
}
void looping(vector<string> plates, int numPlates)
{
for (int i = 0; i < numPlates; i++)
{
for (int j = 0; j < numPlates; j++)
{
int last = plates[i].length() - 1;
cout << plates[i].length() << endl;
if (i == j)
{
// do nothing
}
elseif (plates[i].at(last) == plates[j].at(0))
{
string temp = plates[i+1];
plates[i+1] = plates[j];
plates[j] = temp;
}
}
}
for (int i = 0; i < numPlates - 1; i++)
{
int last = plates[i].length() - 1;
//issues crop up
cout << plates[i].length() << endl;
/*
if (plates[i].at(last) != plates[i+1].at(0))
{
truth = false;
}
*/
}
}
This function tries to sort a bunch of different strings to see if you can match the first and last letter in a chain. Towards the end I seem to be having some issues with the .length function not working with the first plate[0] it seems to try to always say the length is 0. I can't see where it's getting changed to that length? I don't think I modify it anywhere. I'm also struggling with the loop to organize it. I think I could just make loop thats kind of a reverse of the first one I made to organize it in the other direction.