Wondering why this doesn't work. Basically I want to call functions with parameters, change the value of the parameter and have the value changed when the parameter is called again with another function. Without having to return the value.
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <iterator>
#include <list>
using namespace std;
//list<string> List;
//vector<list<string>> vect_list;
typedef list<string> Word_List_Type; //datatyp för att lagra en lista av ord
void read_words(Word_List_Type input_words) {
string s;
string stop = "DONE";
while (s != stop) {
cin >> s;
input_words.push_back(s);
}
input_words.pop_back();
}
void find_words_with_sequential_letters(Word_List_Type &saved_words, Word_List_Type &sequence) {
string word;
string alphabet_small = "abcdefghijklmnopqrstuvwxyz";
vector<string> vect_words;
vector<string> vect_words_2;
int pos;
Word_List_Type::iterator it;
for (it = saved_words.begin(); it != saved_words.end(); it++) {
word = *it;
vect_words.push_back(word);
vect_words_2.push_back(word);
}
for (int i = 0; i < vect_words.size(); i++) {
int num = 0;
for (int j = 0; j < vect_words[i].size(); j++) {
for (int k = 0; k < alphabet_small.size(); k++) {
if (vect_words[i][j] = toupper(vect_words[i][j])) {
vect_words[i][j] = tolower(vect_words[i][j]);
}
if (vect_words[i][j] == alphabet_small[k] && vect_words[i][j+1] == alphabet_small[k+1]) {
num++;
}
}
}
if (num>0) {
pos = i;
sequence.push_back(vect_words_2[pos]);
}
}
}
void print(Word_List_Type &print_words) {
for (string &s : print_words) {
cout << s << endl;
}
}
int main()
{
Word_List_Type words, sequential_words;
cout << "Enter words:" << endl;
read_words(words);
find_words_with_sequential_letters(words, sequential_words);
cout << "Words containing sequential letters:" << endl;
print(sequential_words);
cout << "End of program.";
return 0;
}```