2012-07-16 17 views
11

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

'int wordLength = wordLengthFunction (word);' –

Odpowiedz

16

Nie trzeba "ciąg" w wywołaniu wordLengthFunction().

int wordLength = wordLengthFunction(string word);

powinny być

int wordLength = wordLengthFunction(word);

+0

Świetnie, dzięki za pomoc! – LTK

7

Zmień

int wordLength = wordLengthFunction(string word); 

do

int wordLength = wordLengthFunction(word); 
+0

Świetnie, dzięki za pomoc! – LTK

5

Nie powinno być powtarzanie string udział podczas wysyłania parametrów.

+0

Świetnie, dzięki za pomoc! – LTK

Powiązane problemy