[c++] C++ -- expected primary-expression before ' '

I am new to C++ and programming, and have run into an error that I cannot figure out. When I try to run the program, I get the following error message:

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

I've also tried defining the variables on a separate line before assigning them to the functions, but I end up getting the same error message.

Can anyone offer some advice about this? Thanks in advance!

See code below:

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

This question is related to c++ string function variables

The answer is


You should not be repeating the string part when sending parameters.

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

Change

int wordLength = wordLengthFunction(string word);

to

int wordLength = wordLengthFunction(word);

Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to string

How to split a string in two and store it in a field String method cannot be found in a main class method Kotlin - How to correctly concatenate a String Replacing a character from a certain index Remove quotes from String in Python Detect whether a Python string is a number or a letter How does String substring work in Swift How does String.Index work in Swift swift 3.0 Data to String? How to parse JSON string in Typescript

Examples related to function

$http.get(...).success is not a function Function to calculate R2 (R-squared) in R How to Call a Function inside a Render in React/Jsx How does Python return multiple values from a function? Default optional parameter in Swift function How to have multiple conditions for one if statement in python Uncaught TypeError: .indexOf is not a function Proper use of const for defining functions in JavaScript Run php function on button click includes() not working in all browsers

Examples related to variables

When to create variables (memory management) How to print a Groovy variable in Jenkins? What does ${} (dollar sign and curly braces) mean in a string in Javascript? How to access global variables How to initialize a variable of date type in java? How to define a variable in a Dockerfile? Why does foo = filter(...) return a <filter object>, not a list? How can I pass variable to ansible playbook in the command line? How do I use this JavaScript variable in HTML? Static vs class functions/variables in Swift classes?