0

here is a c++ code .. It compiles fine and looks fine but it messes up the output.

#include<iostream>
#include<string>
using namespace std;

int main() {

        string s;
        cin>>s;

        for(int i=0;i<s.length();i++) {
            if (isalpha (s[i]))
                if (s[i] == 'a'||'A'||'e'||'E'||'i'||'I'||'o'||'O'||'u'||'U')
                        cout<<s[i]<<" is a vowel"<<endl;
                else
                        cout<<s[i]<<" is a consonant"<<endl;

                 if (isdigit (s[i]))
                        cout<<s[i]<<" is a digit"<<endl;
                else
                        cout<<s[i]<<" is a special character"<<endl;
        }
}
~                                                                                                                                          
~

Can someone tell me where I am going wrong please ?

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Salem
0

> if (s == 'a'||'A'||'e'||'E'||'i'||'I'||'o'||'O'||'u'||'U')
You need to say if ( s[i] == 'a' || s[i] == 'A' || I'm sure you get the idea.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.