# Thread: arrays-idea to solve program

1. ## arrays-idea to solve program

hi,
i have this program which read 20 char and count the number of small vowel letters then change them to capital

so i start 2 arrays so i have this idea to solve it
Code:
```int i,v=0;
char a[20]
char v[5]={'e','a','u','i','o'}

for(i=0;i<20;i++)
cin>>a[i];

for(i=o;i<20;i++)
if(a[i]==v[5])
{
v++;
a[i]=a[i]-'A'+'a';
}

for(i=0;i<20;i++)
cout<<a[i];
cout<<"number of small vowel is ="<<v;```

2. What's up with the gigantic font? Are you trying to be annoying?

On line 9, I'm guessing that you're trying to compare a character to the whole array of vowels. C++ doesn't work that way. You'll need to loop through the vowel array, just like you're looping through the input string. Even better yet, break that out into a function called IsVowel or something.

3. sorry a bout the font size i didn't mean it

but why i need vowels loop when the vowels loop are known just in 5 numbers of all

4. can i say this in line 9
Code:
`if(a[i]=='a'||'e'||'u'||'i'||'o')`

5. Originally Posted by CinQabas
can i say this in line 9
Code:
`if(a[i]=='a'||'e'||'u'||'i'||'o')`
No, you need to spell out each comparison separately, like this:
Code:
`if (foo == 'b' || foo == 'a' || foo == 'r')`

6. Code:
```char v[5]={'e','a','u','i','o'}

// ...

if(a[i]==v[5])```
Apart from the comments in the above posts, you're accessing the array out of bounds here, since with a size of 5, the valid indices are 0 - 4.

7. Originally Posted by GReaper
No, you need to spell out each comparison separately, like this:
Code:
`if (foo == 'b' || foo == 'a' || foo == 'r')`
yes i get you

8. Originally Posted by Matticus
Code:
```char v[5]={'e','a','u','i','o'}

// ...

if(a[i]==v[5])```
Apart from the comments in the above posts, you're accessing the array out of bounds here, since with a size of 5, the valid indices are 0 - 4.

i didn't get you
do you mean that my vowel array need to be same size the array of a[20] so he can compere between them ?

or my work is right ?

9. No, what they meant was that you don't use the "v" array properly here. You access one element past the array, and out-of-boundary accesses invoke undefined behavior.

What you're trying to do is to compare each character in the string with all those lowercase vowels, and replace them with uppercase ones. Now, there are multiple ways you can do this, here are some( but there are more ):
Solution #1:
Code:
```bool isLowerVowel = false;
for (int j = 0; j < 5; j++) {
if (a[i] == v[j]) {
isLowerVowel = true;
break;
}
}
if (isLowerVowel)```
Solution #2:
Code:
`if (a[i] == 'a' || a[i] == 'e' || a[i] == 'u' || a[i] == 'i' || a[i] == 'o')`

10. One way could be
Code:
```if ( strchr("aeiou",c) != NULL ) {
// c is a vowel
}```