Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:26:03+00:00 2026-06-07T21:26:03+00:00

When I compile my program, I get the following error message: stringPerm.cpp: In function

  • 0

When I compile my program, I get the following error message:

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

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

What is the cause, and how can the problem be fixed?

Here is the code:

#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);
    }    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:26:05+00:00Added an answer on June 7, 2026 at 9:26 pm

    You don’t need “string” in your call to wordLengthFunction().

    int wordLength = wordLengthFunction(string word);

    should be

    int wordLength = wordLengthFunction(word);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error when I try to compile my C# program: The
I am trying to compile the following program: #include <iostream> int main(){ std::cout <<
I get the following two error messages when I compile the below code for
I get following error with following Objective-C code, while trying to compile it with
I've written a program of the following form: #include stuff_I_need.h int main(){ construct_array(); //
I got a situation, I can't get a program compile since I splitted the
When I compile my program, I get three undefined reference to 'PrintArgv(...)' errors. I
When I try to compile my program on ubuntu using gcc, i get these
I compile my C++ program to LLVM IR using the following command. clang++ -O4
I am getting the following error message when compiling or attempting to run my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.