Help

Please help, here's the question and what I have. Let me know if I'm on track:

Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false.



bool isVowel(char c='A'||'E'||'I'||'O'||'U');

int main()

{
char ch
if (ch==c) {
return 1;
}
else {
return 0;
}

}
The code is totally invalid.
You have the right idea. Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
cin >> ch;
if (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') {
return 1;
}
else {
return 0;
}
}


All you need to do from here is prompt the user to enter a character, then assign that input to ch. Also, what happens if the user enters a lowercase character?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main()
{

}

bool isVowel()
{

    char letter;

    if (letter== ('a' || 'A' || 'e' || 'E' || 'i' || 'I' || 'o' || 'O' || 'u' || 'U'))
    return true;
    else
    return false;
}
Last edited on
Thanks everyone, I'll try them.
yeah but he has to make it into a function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

using namespace std;

bool isVowel(char);

int main()
{
     char letter;
     cin>> letter;
     return (isVowel(letter) == 1);
}

bool isVowel(char letter)
{
     switch(letter)
     {
          case 'a':
          case 'e':
          case 'i':
          case 'o':
          case 'u':
               return true;
               break;
          default:
               return false
     }
}
You might want to take a look at tolower() or toupper() to allow the user to enter uppercase letters
http://www.cplusplus.com/reference/clibrary/cctype/toupper/
http://www.cplusplus.com/reference/clibrary/cctype/tolower/

You need to #include <cctype>
okay, I'm trying to do part 2 of this...and I'm just not understanding c++. I have to prompt user to input sequence of letters and output the number of vowels, here's my botch job, I have no clue where to go.

#include <iostream>
#include <string>

using namespace std;

bool isVowel();
string sequence;
int numberOfVowels;

int main()
{

cout << "Type some letters: "<<;


}
bool isVowel()

{

char letter;

if (letter== ('a' || 'A' || 'e' || 'E' || 'i' || 'I' || 'o' || 'O' || 'u' || 'U'))
return true;
else
return false;
}
"letter" has no way of getting into the function isVowel unless it is passed as a parameter. Use cin >> to get the user's input and assign it to letter. Then make a call to the function isVowel(letter) and output the return value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>

using namespace std;

bool isVowel(char letter);
char letter;
int numberOfVowels;

int main()
{

    cout << "Type some letters: ";
    cin >> letter;
    cout << isVowel(letter);

    return 0;

}

bool isVowel(char letter)
{
    letter = toupper(letter);
    if (letter =='A'||letter=='E'||letter=='I'||letter=='O'||letter=='U')
    return true;
    else
    return false;
}
Topic archived. No new replies allowed.