Simple Vowel Program Help (please :D)

0 Lé Pig · October 20, 2015
Alright. So I am trying to write a program and it is homework, and it is from scratch. Basically I'm creating a user defined function that tells you whether the char you're passing through is a vowel or not. This program actually used to work for the first few builds and now suddenly it doesn't. Every time I build and run using Codeblocks it keeps running the same exact project from a while ago. Let's see if I can get this code to look right on the forums.... nope. Also, if anyone can tell me what I'm doing wrong when I try to use the "code" tool in the forums. It cuts my code in half every time I use it. Sorry, I can't make it easier to read.



#include <iostream>

using namespace std;

bool isVowel(char vowels);

int main()
{
    isVowel('a');
}

bool isVowel(char vowels)
{


if (vowels== 'a' || 'e' || 'i' || 'o' ||'u')
    {

cout << "Is a vowel";
return true;
}else{
return false;
cout << "Is not a vowel";

}
}




Post a Reply

Replies

Oldest  Newest  Rating
0 c student · October 20, 2015
how well do you know if statements and function parameters?
bool isVowel(char vowels)
{
   if (vowel == 'a' || 'e' || 'i' || 'o' ||'u')    // is this right?
       ...
   ...
0 Lé Pig · October 20, 2015
I feel like I have a pretty good understanding of them. Sorry, the "vowel" in the if statement is supposed to be "vowels" i'll fix that in the post. I changed it in the actual IDE and I was still having the same problem.
0 Lé Pig · October 20, 2015
EDIT


This is what I've come up with and it seems to work. Does it look good to you?



char isVowel(char vowel){

if (vowel == 'a' || vowel =='e' || vowel == 'i' || vowel == 'o' || vowel == 'u'){
    cout << "A vowel";
    return true;

}else{
    cout << "Not a vowel";
    return false;
}
}
0 c student · October 20, 2015
yep looks fine.
  • 1

C++

107,190 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator