• Register
2 votes
32 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

Please log in or register to answer this question.

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 16 views
0 votes
1 answer 15 views
0 votes
1 answer 48 views
48 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, 2020 jwilliam 3.9k points
0 votes
1 answer 8 views
8 views
Problem Hey, I was writing a class for finding the average of grades outside the class but I Am facing an error named expected initializer before token. Can someone help me to resolve this error Here is my code Program:  #include <iostream> using std::cout; using std::cin; ...   computeAverage = computeAverage + gradeAverage.getGrade();     }     cout << computeAverage/5 << endl;     return 0; }
asked Dec 22, 2020 chris jordan 2.2k points
1 vote
1 answer 37 views
37 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, 2020 Martin K 6.6k points
0 votes
1 answer 5 views
5 views
Problem: I'm just learning C++, coming out of python3 and QBASIC, and am having a very hard time reading the compiler errors and understanding them, making it difficult to debug. The problem I am having is that I keep pulling the compilation-error: error: expected unqualified-id This occurs on the 10th and 18th line. I am trying to compile this program using linuxs' g++:
asked Dec 15, 2020 Mashhoodch 5.6k points
0 votes
1 answer 38 views
38 views
Problem: I have't coded in c++ for some time and I got stuck when I tried to compile this simple snippet: class A { public: void f() {} }; int main() { { A a; a.f(); // works fine } { A *a = new A(); a.f(); // this doesn't } }
asked Dec 26, 2020 Mashhoodch 5.6k points
0 votes
1 answer 3 views
3 views
Problem: I have this following code: int M = 3; int C = 5; int match = 3; for ( int k =0; k < C; k ++ ) { match --; if ( match == 0 && k = M ) { std::cout << " equals" << std::endl; } } But it gives out an error saying: Error: expression must be a ... trying to modify "match" or "k" value here, but why this error? if I only write it like: if ( match == 0 ) it is ok. Could someone explain it to me?
asked Dec 23, 2020 Mashhoodch 5.6k points
0 votes
1 answer 13 views
13 views
Problem: Hello programmers! I am learning to program, and I just got a little confused about boolean values and logical operators. I tried to run the following program: #include<iostream> using namespace std; int main() { bool check = false && true || true; ... program, I got the following output: Condition evaluated to true I am so confused about how this condition evaluates to true. Any help?
asked Dec 18, 2020 Code Learner 5.5k points
0 votes
1 answer 10 views
10 views
I&rsquo;m getting invalid operands in binary expression in c++. Any idea how to solve?
asked Dec 7, 2020 TeamScript 9.5k points