Aktualizacja: Dziękuję wszystkim za szybkie odpowiedzi - problem rozwiązany!C++ - oczekiwane wyrażenie pierwotne przed "
Jestem nowicjuszem w C++ i programowaniu i napotkałem błąd, którego nie potrafię wymyślić. Kiedy próbuję uruchomić program, pojawia się następujący komunikat o błędzie:
stringPerm.cpp: In function ‘int main()’:
stringPerm.cpp:12: error: expected primary-expression before ‘word’
Próbowałem zostały również definiowanie zmiennych w osobnej linii przed przypisaniem ich do funkcji, ale w końcu się ten sam komunikat o błędzie .
Czy ktoś może udzielić porady na ten temat? Z góry dziękuję!
patrz kod poniżej:
#include <iostream>
#include <string>
using namespace std;
string userInput();
int wordLengthFunction(string word);
int permutation(int wordLength);
int main()
{
string word = userInput();
int wordLength = wordLengthFunction(string word);
cout << word << " has " << permutation(wordLength) << " permutations." << endl;
return 0;
}
string userInput()
{
string word;
cout << "Please enter a word: ";
cin >> word;
return word;
}
int wordLengthFunction(string word)
{
int wordLength;
wordLength = word.length();
return wordLength;
}
int permutation(int wordLength)
{
if (wordLength == 1)
{
return wordLength;
}
else
{
return wordLength * permutation(wordLength - 1);
}
}
'int wordLength = wordLengthFunction (word);' –