I GOT STOCK ON AN ERROR CHAR* TO CHAR FPERMISSIVE

#include<iostream>
#include<cstring>

using namespace std;

char word[20];
char a[1]={a};
char e[1]={e};
char i[1]={i};
char o[1]={o};
char u[1]={u};

int x,y,z;

int main()
{
cout<<"Enter a Word: "<<endl;
cin>>word;
y=strlen(word);

for(z=0;z<y;z++)
{
if (word[z]==a[0])
{
x++;
}
if (word[z]==e[0])
{
x++;
}
if (word[z]==i[0])
{
x++;
}
if (word[z]==o[0])
{
x++;
}
if (word[z]==u[0])
{
x++;
}
else
{
cout<<"No Vowels Found";
}
}
return 0;
}


//heres the code.. please help me
If you mean the character a you need to write 'a'.

 
char a[1]={'a'};
sir i run it it keeps saying no vowels found how?? can you help me??
Hi, please use code tags for your code to make it easier to read - http://www.cplusplus.com/articles/jEywvCM9/

There is no reason to have an array of size 1. Why not just do char e = 'e'; char i = 'i'; charo = 'o';

What's the point of the array?

Or even better, use an array, but put all these vowels in there - char vowels[5] = {'a','e','i','o','u'};

Edit: http://www.cplusplus.com/forum/beginner/185175/
Last edited on
can you fix my program?? please?
@TarikNeaj asked you to use code tags for a reason. All you did was ask for somebody to do your work for you.

Code tags make it much easier to read your code and provide line numbers we can reference when offering you help (in line 5...).

Also, @TarkiNeaj's comment about arrays of 1 is important. The multiple single-char arrays are actually confusing things a bit, making it more difficult to follow what you are doing. Granted, his post did not solve your problem, but his comments would make your code cleaner and easier to follow--and you might even be able to figure out the problem by yourself at that point.

That being said, I hesitate to tell you what the problem is until you make the changes @TarikNeaj suggests. But I will anyway.

The else statement in line ... (see why code tags are helpful?) only applies to the immediately preceding if statement (line ?). So for every letter that is not a 'u', your program will print out "No vowels found".

Make changes to your program and post your new code (with code tags) and we can give you some pointers on how to improve it.

Edit: fixed grammar.
Last edited on
@dvillfranca20

We can also compile your code using cpp.sh - there is a gear icon at the top right of the code snippet. This is a big advantage for you, we don't have to start a new project in our own system in order to help you, so you would probably get more replies.
Topic archived. No new replies allowed.