2012-07-16 23 views
11

Güncelleme: Herkese hızlı yanıtlarınız için teşekkürler - sorun çözüldü!C++ - beklenen birincil ifade ''

C++ ve programlama konusunda yeniyim ve anlayamadığım bir hatayla karşılaştım. Ben program çalıştırmayı denediğimde şu hata mesajını alıyorum: Ben de fonksiyonlara atamadan önce ayrı bir satırda değişken tanımlama denedim

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

ama aynı hata mesajı alıyorum sonunda .

Bu konuda herhangi bir tavsiye önerisi olan var mı? Şimdiden teşekkürler! Aşağıda

bakınız kodu:

#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 sözcük uzunluğu = wordLengthFunction (kelime); Yardımlarınız için' –

cevap

16

için.

int wordLength = wordLengthFunction(string word);

parametreleri gönderirken string bölümünü tekrar edilmemelidir

int wordLength = wordLengthFunction(word);

+0

Harika, yardımlarınız için teşekkürler! – LTK

7

Değişim Sen wordLengthFunction() çağrınızda "dize" gerekmez

int wordLength = wordLengthFunction(string word); 

int wordLength = wordLengthFunction(word); 
+0

Mükemmel, teşekkürler! – LTK

5

olmalıdır.

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

Harika, yardımlarınız için teşekkürler! – LTK

İlgili konular