mercredi 6 janvier 2021

using loop for only if statement and then print else statement

Check whether if the entered character is consonant or vowel?

I almost got the result but I just need else statement to be out of loop. Is it possible to use else out of loop? Here I tried adding {} but didn't help me. How do I do so ? I have solved this program in many ways but I want to clear my concepts of if and loop.

#include <iostream>
    
using namespace std;

int main(){
    char x ;
    char vowel[10] ={'a','e','i','o','u','A','E','I','O','U'};
    cout<<"Enter ";
    cin>>x ;
    for(int i = 0 ; i<10 ; i++)
    {
        {    
            if(x ==vowel[i])
            {
                cout<<"This is a vowel";
            }
        }   
        else
        {
            cout<<"This is a consonant";
        }   
    }
    return 0 ;
}

Aucun commentaire:

Enregistrer un commentaire