私はC++とプログラミングに不慣れで、理解できないエラーに遭遇しました。プログラムを実行しようとすると、次のエラーメッセージが表示されます。
stringPerm.cpp: In function ‘int main()’:
stringPerm.cpp:12: error: expected primary-expression before ‘word’
また、関数に割り当てる前に別の行で変数を定義しようとしましたが、同じエラーメッセージが表示されます。
誰かがこれについていくつかのアドバイスを提供できますか?前もって感謝します!
以下のコードを参照してください。
#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);
}
}