include include using namespace std void displaymenu int cou

#include <iostream>
#include <cctype>

using namespace std;

void displaymenu();
//int count_vowels(char *str);

int main()
{
    string sentence;
    int a = 0;
    int num_vowels =0;
    cout << \"enter a sentence or phrase: \" << endl;
    getline(cin, sentence);
    string *phrase = nullptr;
    phrase = &sentence;
    cout << \"/......................../\" << endl;
    cout << \"your sentence or phrase: \" << *phrase << endl;

    char choice;
    do
    {

        displaymenu();
        cin >> choice;
        switch(choice)
        {
        case \'A\':

            cout << \"Count the number of vowels in the string: \" << endl;
          // num_vowels =count_vowels(phrase);
            while(*phrase!=\"\\0\")
           {
             if(*phrase == \"a\" || *phrase == \"e\" || *phrase == \"i\" || *phrase == \"o\" || *phrase == \"u\")
                {

                    a++;
                    phrase++;
                }

            }
            cout << \"The number of vowels: .................... \" << a << endl;

        break;

        }

    }while(choice == \'D\');

    return 0;
}
void displaymenu()
{
    cout << \"/......................../\" << endl;
    cout << \"Menu:\" << endl;
    cout << \"Enter A: Count the number of vowels in the string: \" << endl;
    cout << \"Enter B: Count the number of consonants in the string: \" << endl;
    cout << \"Enter C: Count Both the vowels and consonants in the string: \" << endl;
    cout << \"Enter D: Enter another string: \" << endl;
    cout << \"Enter E: Exit the program: \" << endl;
}

*************HELP WILL NOT RUN - GETS HUNG UP - WHAT AM I DOING WRONG THANKS C++ READ IN A STRING COUNT VOWELS HAVE TO USE POINTERS

Solution

string sentence;
    int a = 0;
    int num_vowels =0;
    cout << \"enter a sentence or phrase: \" << endl;
    getline(cin, sentence);
    string *phrase = nullptr;
    phrase = &sentence;
    cout << \"/......................../\" << endl;
    cout << \"your sentence or phrase: \" << *phrase << endl;

Instead of above part try to use these:

char sentence[1000];
    int a = 0;
    int num_vowels =0;
    cout << \"enter a sentence or phrase: \" << endl;
    getline(cin, sentence);
char *phrase = nullptr;
    phrase = sentence;
    cout << \"/......................../\" << endl;
    cout << \"your sentence or phrase: \" << *phrase << endl;

phrase = &sentence;

this statement is wrong. you are storing the address of string object into a string pointer.

#include <iostream> #include <cctype> using namespace std; void displaymenu(); //int count_vowels(char *str); int main() { string sentence; int a =
#include <iostream> #include <cctype> using namespace std; void displaymenu(); //int count_vowels(char *str); int main() { string sentence; int a =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site