Mehboob
Mehboob

Reputation: 11

How to print vowels from array

Hey dear able to honor!

I'm writing a program of my assignment in which I'll need to show my full name and my I'd. using an array and also find vowels from my name and show them one by one in a column and also total numbers of vowels at the end. I did the first target and also done showing the total number of vowels, while I try too much to show vowels one by one with numbers like the following picture but I can't anyone can help so, please...

This image shows how to print out vowels

if the Image is not open so image text is like something this:

My first name is: Bilal
MY I'd is: bc1234567890
last digit of i'd is: 0

vowel no 1 is: i
vowel no 2 is: a

Total vowels in my first name: 2

I tried this:

//for first name vowels
for(i1=0;i1<n1a[i1];i1++)
{
    switch(n1a[i1])
    {
        case 'A':
        case 'a':
        case 'E':
        case 'e':
        case 'I':
        case 'i':
        case 'O':
        case 'o':
        case 'U':
        case 'u':
        counter1++;
        break;
    }
    for(y=1;y<=counter1;y++)
    {
        cout<<"Vowel "<<y<<" is: "<<n1a[i1]<<endl;
    }
}
cout<<endl;
cout<<"Total Vowels Is/Are: "<<counter1<<endl;

Upvotes: 0

Views: 225

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311048

It seems you mean the following for loop

for(i1=0; n1a[i1] != '\0'; i1++)

Within the switch statement write

for(i1=0; n1a[i1] != '\0'; i1++)
{
    switch(n1a[i1])
    {
        case 'A':
        case 'a':
        case 'E':
        case 'e':
        case 'I':
        case 'i':
        case 'O':
        case 'o':
        case 'U':
        case 'u':
        counter1++;
        std::cout << "Vowel no " << counter1 << ": " << n1a[i1] << '\n';
        break;
    }
    //...
 

Or if the variable n1a has the type std::string then

for ( char c : n1a )
{
    switch( c )
    {
        case 'A':
        case 'a':
        case 'E':
        case 'e':
        case 'I':
        case 'i':
        case 'O':
        case 'o':
        case 'U':
        case 'u':
        counter1++;
        std::cout << "Vowel no " << counter1 << ": " << c << '\n';
        break;
    }

Upvotes: 1

Related Questions