Questions icon indicating copy to clipboard operation
Questions copied to clipboard

Can someone help me with this switch statement

Open riden-with-biden opened this issue 2 years ago • 0 comments

#include using namespace std; int count_vowel(char*); int count_con(char*); int main() { const int size = 81; char input[size];

cout << "Enter a sentence no longer than " << (size - 1) << " characters: " << endl;
cin.getline(input, size);
char choice;


do
{
    cout << "Please enter A to E from following: " << endl;
    cout << "A. Count the number of vowels in the string " << endl;
    cout << "B. Count the number of consonants in the string " << endl;
    cout << "C. Count the number of vowels and consonants in the string " << endl;
    cout << "D. Enter another string " << endl;
    cout << "E. Exit the program" << endl;
    cin >> choice;
    switch (toupper(choice))
    {
    case 'A':
    {

        int count = count_vowel(input);
        cout << "Number of vowel:" << count << endl;
        break;

    }

    {
    case 'B':
        int count_ = count_con(input);

        cout << "Number of conostants: " << count_ << endl;

    }
    }

} while (toupper(choice) != 'E');

} int count_vowel(char* str) { int counter = 0; char vowel[] = { 'A','E','I','O','U' }; while (*str != '\0') { char temp = toupper(*str); //convert char into upper to avoid lower condition for (int i = 0; i < 5; i++) { if (temp == vowel[i])counter++; }

    str++;
}
return counter;

} int count_con(char* str_) { int counter_ = 0; char vowel_[] = { 'A','E','I','O','U' }; while (*str_ != '\0') { char temp = toupper(*str_); //convert char into upper to avoid lower condition for (int i = 0; i < 5; i++) { if (temp != vowel_[i])counter_++; }

    str_++;
}
return counter_;

}'

My count_con functioin isn't returning the correct answer

riden-with-biden avatar Oct 06 '23 07:10 riden-with-biden