Click to See Complete Forum and Search --> : Sort THis Then..


Scream
12-05-2000, 12:37 PM
Hi This program is meant to say if there is a vowl in a string. I have just
started it but it dosnt work
what am i doing wrong is the switch wrong do i have to use IFs or what?
Thank You
My Current Code:

#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <string.h>

int main(void)
{
char string[30];
cout<<"Enter a string
";
cin.getline(string, sizeof(string), '
');
cout<<endl;


int i;

for(i=0; i < strlen(string); i++);
{
switch(string[i])
{
case 'i' : cout<<"Letter I
";
default : cout<<"No Vowls
";
}

}



system("pause");
return 0;
}

Danny Kalev
12-05-2000, 02:49 PM
You need to list all the vowels in the switch statement, not just 'i'.
Also, you want to use the isalpha() function (declared in <cctype>) to
check whether the char is a letter and not, say, a whitespace,
punctuation etc.

Danny

Scream wrote:
>
> Hi This program is meant to say if there is a vowl in a string. I have just
> started it but it dosnt work
> what am i doing wrong is the switch wrong do i have to use IFs or what?
> Thank You
> My Current Code:
>
> #include <stdlib.h>
> #include <iostream.h>
> #include <fstream.h>
> #include <string.h>
>
> int main(void)
> {
> char string[30];
> cout<<"Enter a string
> ";
> cin.getline(string, sizeof(string), '
> ');
> cout<<endl;
>
> int i;
>
> for(i=0; i < strlen(string); i++);
> {
> switch(string[i])
> {
> case 'i' : cout<<"Letter I
> ";
> default : cout<<"No Vowls
> ";
> }
>
> }
>
> system("pause");
> return 0;
> }