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 4600338
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:40:11+00:00 2026-05-21T23:40:11+00:00

i cant seem to figure out what wrong for some reason it wont compile

  • 0

i cant seem to figure out what wrong

for some reason it wont compile and it think theres a problem on my jumbleString function

#include <iostream>
#include <iomanip>
#include <string>
#include <istream>

using namespace std;

int main ()
{
    int lengthofstring, x, countWords(string str), countConsonant(string str, int), consonant, jumbleString(string str);
    string str, str2, wordone;

    char options;
    cout << "Please enter a word, a sentence, or a string of numbers." << endl;

    getline(cin, str);

    //cin >> str;

    lengthofstring = str.length(); 
    str2=str;

    bool another= true;

    while (another) 
    {
        cout << '\n' << "USE THIS MENU TO MANIPULATE YOUR STRING" << endl;
        cout << "---------------------------------------" << endl;
        cout << "1) Inverse String" << endl;
        cout << "2) Reverse String" << endl;
        cout << "3) To Uppercase" << endl;
        cout << "4) Jumble String" << endl;
        cout << "5) Count Number Words" << endl;
        cout << "6) Count Consonants" << endl;
        cout << "7) Enter a Different String" << endl;
        cout << "8) Print the String" << endl;
        cout << "Q) Quit" << endl;

        cin >> options;

        switch (options)
        {
        case '1':
            for (x = 0; x < lengthofstring; x++)
            {
                if (islower(str[x]))
                    str[x] = toupper(str[x]);
                else if (isupper(str[x]))
                    str[x] = tolower(str[x]);

            }
            cout<< str;
            break;
        case '2':
            for (x = 0; x < lengthofstring; x++)
            {
                str2[x] = str[lengthofstring-1-x];
            }
            cout<< str2;
            break;
        case '3':
            {
                for (x = 0; x < lengthofstring; x++)
                { 
                    if (islower(str[x]))
                        str[x] = toupper(str[x]);
                }
                cout<< str;
            }
            break;
        case '4':
            jumbleString(str);
            break;

        case '5':
            cout << countWords(str);
            break;
        case '6': 
            consonant = 0;
            cout<< countConsonant(str, consonant);
            break;
        case '7':
            cout << "Please enter another word, a sentence, or a string of numbers." << endl;
            cin.ignore();
            getline(cin, str);
            cout << str <<endl;
            break;
        case '8':
            cout<< str2;
            break;
        case 'q':
            another = false;
            break;
        }
    }

    cin.get();
    cin.get();
    return 0;
}

void jumbleString(string str)
{
    int length = str.length();
    int  j, k;

    for(int i = 0; i < length; j++)
    {
        k = rand() % length;
        j = rand() % length;
        char c = str[j];
        str[j] = str[k];
        str[k] = c;
    }

    cout << str<<endl;
}

int countWords(string str)
{
    int length = str.length();
    int words = 1;
    for(int size = 1; length > size; size++)
    {
        if (str[size] == ' ' && str[size-1] != ' ')
            words++;
    }
    if (str[0] == ' ')
        words--;
    return words;
}
int countConsonant(string str, int consonant)
{
    int length = str.length();
    consonant = 0;

    for (int i = 0; i < length; i++)
    {
        if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && 
            str[i] != 'o'&& str[i] != 'u' && str[i] != 'A' && str[i] != 'E' 
            && str[i] != 'I' && str[i] != 'O' && str[i] != 'U' && str[i] != ' '&& str[i] != '1'
            && str[i] != '2' && str[i] != '3' && str[i] != '4' && str[i] != '5' && str[i] != '6'
            && str[i] != '7' && str[i] != '8' && str[i] != '9' && str[i] != '0')
            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-21T23:40:12+00:00Added an answer on May 21, 2026 at 11:40 pm

    the problem is changing i inside the loop (I guess you meant to change k):

    if you did mean to set k, change i = rand() % length; into k = rand() % length;

    also, your question is a variant of the permutation problem, which Fisher-Yates solves. I would suggest looking at it, you will probably get better “randomness” by using it.

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

Sidebar

Related Questions

I can't seem to figure out what I am doing wrong here. I publish
Can't seem to figure out where Im going wrong here: private static String generateHashFromFile(String
I'm trying to figure out what I'm doing wrong here, but I can't seem
I can't seem to figure out a good way to do this, but it
I can't seem to figure out how to set the default database in Sql
Can anyone explain how compilation works? I can't seem to figure out how compilation
I can't seem to figure this out. I'm experimenting with MVC Beta and am
I'm having a problem with my Seam code and I can't seem to figure
I have another script that I can't figure out what is wrong with it.
This is more of a business-oriented programming question that I can't seem to figure

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.