2012-07-16 3 views
11

업데이트 : 빠른 응답을 보내 주셔서 감사합니다 - 문제가 해결되었습니다!C++ - 예상 기본 표현식이 '

저는 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); 
    }  
} 
+5

'int wordLength = wordLengthFunction (word);' –

답변

16

에.

int wordLength = wordLengthFunction(string word);

매개 변수를 보낼 때 당신은 string 부분을 반복해서는 안

int wordLength = wordLengthFunction(word);

+0

위대한, 도와 줘서 고마워! – LTK

7

변경 당신은 wordLengthFunction()에 전화에서 "문자열을"필요하지 않습니다

int wordLength = wordLengthFunction(string word); 

int wordLength = wordLengthFunction(word); 
+0

도움 주셔서 감사합니다. – LTK

5

해야한다.

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

도움을 주셔서 감사합니다. – LTK

관련 문제