Write a program that reads a character and then prints “It is a vowel”, if it is a vowel, “It is an operator”, if it is one of the five operators, and “It is something else”, if it is anything else.
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
bool isVowel(char character) {
string vowels = "AEIOUYaeiouy";
for (int j = 0; j < vowels.size(); j++)
{
if (toupper(character) == toupper(vowels[j]))
{
return true;
}
}
return false;
}
bool isOperator(char character) {
string operators = "^&|~.";
for (int j = 0; j < operators.size(); j++)
{
if (toupper(character) == toupper(operators[j]))
{
return true;
}
}
return false;
}
int main()
{
char character;
cout<<"Enter character: ";
cin>>character;
if(isVowel(character)){
cout<<"It is a vowel\n\n";
}else if(isOperator(character)){
cout<<"It is an operator\n\n";
}else{
cout<<"It is something else\n\n";
}
system("pause");
return 0;
}
Comments
Leave a comment