Using a do…while() loop, continuously scan for characters (one per line) and print it out afterwards.
The loop shall terminate due to either of the following reasons:
The inputted character is a vowel
The number of inputted characters has already reached 5.
#include <iostream>
using namespace std;
int main()
{
char letter;
int count=0;
do{
cout<<"Enter letter: ";
cin>>letter;
cout<<letter<<"\n";
char c = tolower(letter);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
break;
}
count++;
} while(count<5);
system("pause");
return 0;
}
Comments
Leave a comment