0

Learning C++ in college right now, and for one project I had to write a program that lists all permutations of different names. The code works fine on repl.it, but on Zybooks(the website used for class) I get an error. What do I do?

#include <vector>
#include <string>
#include <iostream>

using namespace std;

void AllPermutations(vector<string> &permList, vector<string> &nameList) {
   string tmpName;
   int i;
   
   if (permList.size() == 3){
      for (i = 0; i < permList.size(); ++i){
         cout << permList.at(i) << " ";}
         cout << endl;
}
   else {
      for (i = 0; i < nameList.size(); ++i){
         tmpName = nameList.at(i);
         nameList.erase(nameList.begin() + i);
         permList.push_back(tmpName);
         
         AllPermutations(permList, nameList);
         
         nameList.insert(nameList.begin() + i, tmpName);
         permList.pop_back();
         }
   }
}
int main() {
   vector<string> nameList(0);
   vector<string> permList(0);
   string name;
   
   getline(cin,name);
   
   while (name != "-1"){
      nameList.push_back(name);
      getline(cin,name);
      }
   
   AllPermutations(permList, nameList);
   return 0;
}
  • Write a bug ticket? At least inform the people that are your teachers, so they can fix the issue? However, when doing so, be clear with what you did. It's not completely clear whether compiling caused errors or running the compiled code. Also, what exact output do you get? BTW: As a new user here, please take the [tour] and read [ask]. Concerning code in questions, make sure they are a [mcve] and consistently formatted. – Ulrich Eckhardt Nov 10 '20 at 19:32
  • 1
    Do you know the input that causes the problem? If you do then you can use that input and *debug* your application to see what it does. Like using a *debugger* to step through your code statement by statement. I'm assuming that the issue isn't really with the compilers themselves, but rather dues to a problem in your program. – Some programmer dude Nov 10 '20 at 19:32
  • Also, I really recommend that you set up an environment to build and run programs at home if you can. For debugging, you really need to do it locally. – Some programmer dude Nov 10 '20 at 19:39

0 Answers0