Actualización: ¡Gracias a todos por sus rápidas respuestas - problema resuelto!C++ - expresión primaria esperada antes de ''
Soy nuevo en C++ y la programación, y he encontrado un error que no puedo entender. Cuando trato de ejecutar el programa, aparece el siguiente mensaje de error:
stringPerm.cpp: In function ‘int main()’:
stringPerm.cpp:12: error: expected primary-expression before ‘word’
También he intentado definir las variables en una línea separada antes de asignarlos a las funciones, pero me acaban de recibir el mismo mensaje de error .
¿Alguien puede dar algunos consejos al respecto? ¡Gracias por adelantado!
Ver código de abajo:
#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);
}
}
'int longitud de palabra = wordLengthFunction (palabra);' –