Array 1D


Why consonat didnt appear? someone help me. Really need help.

#include<iostream>
using namespace std;

int main()
{
char dta[100];
int num,i;

cout<<"How many character : ";
cin>>num;

for(int i=0 ; i<num ; i++)
{
cout<<"Enter character NO."<<i+1<<": " ;
cin>>dta[i];
}



for(int i=0 ; i<num ; i++)
{

if(dta[i]!='a' || dta[i]!='A' ||
dta[i]!='e' || dta[i]!='E' ||
dta[i]!='i' || dta[i]!='I' ||
dta[i]!='o' || dta[i]!='O' ||
dta[i]!='u' || dta[i]!='U' )
{
cout<<"The consonant characters : "<<dta[i]<<endl;
break;
}
}



return 0;
}
Your if statement is always going to be true.
Think about it. If the character is 'A', then not = 'a' will be true.
You want &&, not ||.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
1
2
3
4
5
6
7
8
9
for(int i=0 ; i<num ; i++)
{

if( dta[i]!='a' && dta[i]!='A' && dta[i]!='e' && dta[i]!='E' && dta[i]!='i' && dta[i]!='I' && dta[i]!='o' && dta[i]!='O' && dta[i]!='u' && dta[i]!='U' )
{
cout<<"The consonant characters : "<<dta[i]<<endl;
//break;
}
}
thanks AbstractionAnon and anup30. i really appreciate about it.
hope you guys helps me next time.
Topic archived. No new replies allowed.