Do-While loops

closed account (oy8URXSz)
It's me again and I need your help! I'am currently having difficulties with this problem, create a program that will ask the user to enter a character and that will keep on asking until the program encounters a vowel. (Use do while)
Currently, I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include<string>
using namespace std;
int main()
{
    string letter,a,e,i,o,u;
	
	do
    {
        cout << "Enter a letter: " << endl;
        cin >> letter;
    } while (letter != a && letter != e &&
            letter != i && letter != o && letter != u);
	return 0;
}

But, it still keeps asking after I entered a vowel.
Maybe try the OR logic operators?
the problem is that you declared 6 string variables, and didn't assign any value to the last 5 (the vowels)

so instead, use char
1
2
3
4
5
6
7
8
9
10
char letter;

	do
    {
        cout << "Enter a letter: " << endl;
        cin >> letter;
    } while (letter != 'a' && letter != 'e' &&
            letter != 'i' && letter != 'o' && letter != 'u');
	return 0;
}


make sure to use ' ' (single quotation marks)

computers take a,e,i,o,u as natural characters already, so you don't have to declare char a,e,i,o,u etc...

I suck at explaining but I think that's the best way to put it

Last edited on
i fixed it,with string,like you want.
so,this is your program that i fixed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include<string>
using namespace std;
int main()
{
    string letter,a,e,i,o,u;

	do
    {
        cout << "Enter a letter: " << endl;
        cin >> letter;
    } while (letter != "a" && letter != "e" &&
            letter != "i" && letter != "o" && letter != "u");
	return 0;
}




tell me if i helped.
closed account (oy8URXSz)
@raban thank you for the big help! @apicante thanks for the effort!
ΗΕΥ,mine is working with string like you want,so why not help it?
Topic archived. No new replies allowed.