2012-07-16 9 views
11

更新:皆様、ご返事ありがとうございます。C++ - 'の前の一次式が期待されています'

私はC++とプログラミングには新しく、わからないエラーに遭遇しました。私は、プログラムを実行しようとすると、私は次のようなエラーメッセージが出ます:

stringPerm.cpp: In function ‘int main()’: 
stringPerm.cpp:12: error: expected primary-expression before ‘word’ 

を私はまた、機能に割り当てる前に、別の行に変数を定義しようとしましたが、私は同じエラーメッセージが出てしまいます。

誰でもこれについていくつかのアドバイスを提供できますか?前もって感謝します!

、以下を参照してくださいコード:

int wordLength = wordLengthFunction(word); 
+5

「int wordLength = wordLengthFunction(word);」 –

答えて

16

#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); 
    }  
} 
+0

よろしくお願いします。 – LTK

7

変更

int wordLength = wordLengthFunction(string word); 

あなたはwordLengthFunction()にお電話で "文字列" は必要ありません。

int wordLength = wordLengthFunction(string word);

パラメータを送信するときに、あなたがstring一部を繰り返すべきではありません

int wordLength = wordLengthFunction(word);

+0

あなたのお役に立てありがとうございます! – LTK

5

でなければなりません。

int wordLength = wordLengthFunction(word); //you do not put string word here. 
+0

よろしくお願いします。 – LTK

関連する問題