CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Posts
    7

    Non incrementing loop.

    Good Morning:
    I have been working on this function for two days and I cannot get it to compile. Can someone please help me? Here are the instructions for the function:
    Write a function named analyzeString. This function is passed a null terminated string as the first parameter. The function uses 3 reference parameters to return the number of vowels, the number of consonants, and the number of separator characters. Assume a separator character is a space, a tab, or a newline. The function declaration is as follows:
    void analyzeString (char inputString [], int & numVowels, int & numConsonants, int & numSeparators);
    Here is the code that I have so far:

    /* This program will test the
    "void analyzeString ( char inputString [], int & numVowels,
    int & numConsonants, int & numSeparators)" function*/
    #include <iostream>
    using namespace std;

    void analyzeString ( char inputString [], int & numVowels,
    int & numConsonants, int & numSeparators);
    void main()
    {
    const int SIZE = 100;
    char inputString [SIZE] = {'l', 'D', '\t', ' ', 's','P','\0'};
    int numVowels, numConsonants, numSeparators;
    numVowels = numConsonants = numSeparators = 0;

    analyzeString (inputString, numVowels,
    numConsonants, numSeparators);
    cout << numVowels <<'\n';
    cout <<numConsonants <<'\n';
    cout <<numSeparators <<'\n';
    }


    * This function will count the number of vowels,
    consonants, and separator characters in a string */

    #include <iostream>
    using namespace std;

    void analyzeString ( char inputString [], int & numVowels, int & numConsonants, int & numSeparators)
    {
    char ch;
    ch = inputString[0];
    numVowels = 0;
    numConsonants = 0;
    numSeparators = 0;
    int increment = 0;

    cout << "in funct \n";
    while ( ch != '\0')
    {
    if ( ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85 || //check for vowels
    ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117)
    numVowels++;

    if (( ch != 65 && ch != 69 && ch != 73 && ch != 79 && ch != 85 && //check for consonants
    ch != 97 && ch != 101 && ch != 105 && ch != 111 && ch != 117)
    && (ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122))
    numConsonants++;

    else
    numSeparators++;
    } inputString [increment++];

    }The loop does not increment, it is a runaway.

  2. #2
    Join Date
    Dec 2012
    Posts
    7

    Re: Non incrementing loop.

    I am sorry, It will compile it just doesn't work, it is a runaway.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Non incrementing loop.

    ch never changes inside your loop

  4. #4
    Join Date
    Dec 2012
    Posts
    7

    Re: Non incrementing loop.

    Thank you to everyone. I have resolved this one, now I only have four more to go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured