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

  • SEARCH
  • Home
  • 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 5990411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:14:25+00:00 2026-05-22T23:14:25+00:00

int countConsonant(string str, int consonant) { int length = str.length(); consonant = 0; for

  • 0
int countConsonant(string str, int consonant)
{
    int length = str.length();
     consonant = 0;

        for (int i = 0; i < length; i++)
        {
            if(str[i] == 'b'&& str[i] == 'c' && str[i] == 'd'&& str[i] == 'f'
                && str[i] == 'g'&& str[i] == 'h'&& str[i] == 'j' && str[i] == 'k'&& str[i] == 'l'&& str[i] == 'm'
                && str[i] == 'n'&& str[i] == 'p'&& str[i] == 'q'&& str[i] == 'r'&& str[i] == 's'&& str[i] == 't'
                && str[i] == 'v'&& str[i] == 'w'&& str[i] == 'x'&& str[i] == 'y'&& str[i] == 'z')

                consonant = consonant + 1;
        }
        return consonant;
}
  • 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-05-22T23:14:25+00:00Added an answer on May 22, 2026 at 11:14 pm

    You were close, but should check with logical-or ||, not logical-and && (str[i] simply can’t be equal to two different things).

    The C++03 Standard allows you to use the keywords and and or – and not, xor etc – instead of these cryptic (for new programmers) symbols, but this hasn’t caught on widely – perhaps because Microsoft’s compiler doesn’t default to being Standard-compliant in this regard – presumably to avoid breaking existing client code that has variables, functions, types etc. with these names. So, for portability and simplicity, many libraries and textbooks avoid these keywords too.

    Another approach that might be a little more concise is to use isalpha() from <cctype> then check it’s not a vowel. Faster approaches tend to use arrays from character value to bool, but beware indexing outside the array due to signed character values or >=128 bit non-ASCII values. If there’s also uppercase/lowercase to consider – you may want to use tolower() on your character before testing it (i.e. char c = tolower(str[i])); if (c == '...).

    Other notes: your function should:

    • accept its std::string argument by const reference (i.e. const std::string& str) to avoid unnecessary and time-consuming copying of the value from the calling context into a separate variable local to this function. The copying doesn’t do any real functional harm, but it’s unnecessary.
    • make consonant a local variable rather than a function parameter, as any inputted value is immediately clobbered with 0, and the result it returned by the function rather than written into consonant (which would be impossible as it is passed by value rather than passed by pointer/reference).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int main() { int a[3]={1,10,20}; printf(%u %u %u \n ,&a,a,&a[0]); return 0; } This
int x; printf(hello %n World\n, &x); printf(%d\n, x);
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,
getEmployeeNameByBatchId(int batchID) getEmployeeNameBySSN(Object SSN) getEmployeeNameByEmailId(String emailID) getEmployeeNameBySalaryAccount(SalaryAccount salaryAccount) or getEmployeeName(int typeOfIdentifier, byte[] identifier) ->
Consider: int testfunc1 (const int a) { return a; } int testfunc2 (int const
inline int factorial(int n) { if(!n) return 1; else return n*factorial(n-1); } As I
typeof(int).Name Will return System.Int32 does anyone know of a way to return int
int maxSumRec(const vector<int> &a, int left, int right){ if (left == right){ if (a[left]
int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, test, 5); }
int d() {return 0;} int i() {return 7;} struct a { int(*b)(); }c={d}; typedef

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.