• Register
2 votes
23 views

Problem:

Please find out the problem in my code and let me know where I am wrong.

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

 

12 7 7
15,250 points

1 Answer

1 vote

Solution:

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

Write like this instead of the wrong one.

int wordLength = wordLengthFunction(word);

 

13 9 6
94,240 points

Related questions

0 votes
1 answer 7 views
0 votes
1 answer 4 views
0 votes
1 answer 46 views
46 views
Problem : I want to compile my code to test my function to read and print the data file, but I get the compiling error that I don't understand as follows "Error: expected constructor, destructor, or type conversion before ';' token".
asked Jan 24 jwilliam 3.9k points
1 vote
1 answer 23 views
23 views
Problem: I am in the process of understanding C++ Programming. Currently I am in trouble because of my below C++ program. I have tried to fix it by my own efforts but I am unable to fix the below error. [Error] a function-definition is not allowed here before '{' token ...     mydisplaymenu();     system("pause");     return 0; } I am looking for C++ expert who can help me in fixing above program.
asked May 26 Martin K 6.6k points
0 votes
1 answer 5 views
5 views
Problem : Write a program to evaluate an Infix expression using stack in C++. The program should have infix expression directly in the code.
asked Oct 8 sikandar 2.4k points