Reputation: 19
i made this code to print out vowels from array. i have wrote code before but back then only error was that it was printing whole array instead of just vowels. i wrote it today again i dont think that 2nd time i have made any change in code than the previous one(if i made i cant see) but now it takes blank input of array and ends the program. can u help me out? here is the code:
int size=0;
cout<<"Enter the size of array=";
cin>>size;
char arr[size];
cout<<"Enter the array=";
for(int i=0;arr[i]='\0';i++){
cin>>arr[i];
}
for(int i=0;arr[i]!='\0';i++)
{
if(arr[i]=='a'||'e'||'i'||'o'||'u'||'A'||'E'||'I'||'O'||'U')
{
cout<<arr[i];
}
}
Upvotes: 2
Views: 1426
Reputation: 357
Try this:
#include <iostream>
using namespace std;
int main()
{
int size = 0;
cout << "Enter the size of array=";
cin >> size;
char *arr= new char[size]; /*Requires a pointer to declare a dynamic array or a vector*/
cout << "Enter the letters array " <<endl;
for (int i = 0; i < size; i++) {
cout << i + 1 << " : ";
cin >> arr[i];
}
for (int i = 0; i < size; i++)
{
switch (arr[i])
{ case 'a' :
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
cout << arr[i];
break;
default:
break;
}
}
}
Upvotes: 3