Vowel test boolean return values

I'm trying to test if a character is a vowel. I made a separate function for the test, I'm not really sure how to get my return value to output whenever I call the function from main?

Also, I'm not good with while loops and can't figure out how to get it to continue asking whether or not the user wants to keep entering values.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <cstdlib>
#include <iostream>

using namespace std;

bool isVowel(bool);

int main(int argc, char *argv[])
{
    char var1, cont;
    
    while (cin)
    {
          cout << "Please enter a character. ";
          cin >> var1;
          isVowel(var1);
    }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

bool isVowel(bool)
{
    char var1;
    
    switch (var1)
    {
          case 'A':
          return true;
          break;
          case 'a':
          return true;
          break;
          case 'E':
          return true;
          break;
          case 'e':
          return true;
          break;
          case 'I':
          return true;
          break;
          case 'i':
          return true;
          break;
          case 'O':
          return true;
          break;
          case 'o':
          return true;
          break;
          default:
          return false;
          

    }
    
 return 0;
}
Last edited on
If you want to return the actual word "True" then isVowel has to be a string.

Let me rewrite the code...
I modified it a lot. compare yours and mine.


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;

string isVowel(char var1)
{
	bool s;
	string value;

	switch (var1)
	{
	case 'A':
		s = true;
		break;
	case 'a':
		s = true;
		break;
	case 'E':
		s = true;
		break;
	case 'e':
		s = true;
		break;
	case 'I':
		s = true;
		break;
	case 'i':
		s = true;
		break;
	case 'O':
		s = true;
		break;
	case 'o':
		s = true;
		break;
	default:
		s = false;
	}

	if (s == false)
		value = "False";
	else
		value = "True";

	return value;
}


int main()
{
	char var1, cont;
	bool Repeat = true;
	char YoN;

	while (Repeat)
	{
		cout << "Please enter a character: ";
		cin >> var1;
		cout << endl;
		cout << isVowel(var1) << endl << endl;
		cout << "Want to try again?(Y/N): ";
		cin >> YoN;

		if (YoN == 'Y' || YoN == 'y')
			Repeat = true;
		else if (YoN == 'N' || YoN == 'n')
			return 0;

		cout << endl << endl;
	}
	return 0;
}

Thank you so much!
Topic archived. No new replies allowed.