473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to return a value true if a given char is a vowel and false if not?

3 New Member
i made a program in else-if statement about this problem.
but my teacher requires to give a return statement about this. i am new with in programming and we had just tackle a return statement and i find it hard to understand. please can u help me. or just give me an idea how to do it.
#include <stdio.h>
#include <conio.h>
int main ()
{
char a,e,i,o,u;
char letter,ans;
printf("\n\nent er another letter(1=yes,0= no)?");
scanf("%d",&ans );
if (ans==1){
printf("\nEnter a letter:");
scanf("%d",&let ter);
if (letter == 'a'){
printf("true"); }
else if (letter == 'e'){
printf("true"); }
else if (letter == 'i'){

printf("true");
}
else if (letter == 'o'){

printf("true");
}

else if (letter == 'u'){

printf("true");

}
else
{
printf("false") ;
}
while (ans==1)

getche ();
return 0;}
}
this is my program in if-else staement.
Aug 31 '09
12 10270
whodgson
542 Contributor
@ JosAH
I don`t think that your link explains your solution very well... at least my first shot at applying it to what you wrote left me baffled (failed). Could you amplify a bit. I will dig further.
EDIT:
Tchtch Jos.... first your code would not compile because of null in lower case and then it declared AEIOU were not vowels!
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. int isVowel(char c); 
  4.  
  5. int main()
  6. {
  7. char c;    
  8. cout<<"Enter a character, call isVowel() and find if \n"
  9. <<" TRUE or FALSE\n";
  10. cout<<"Enter a character ";
  11. cin>>c;
  12. if(isVowel(c)==1)
  13. cout<<"The character you entered is a vowel \n";
  14. else cout<<"The character you entered is not a vowel \n";
  15. cout<<endl<<endl;
  16. system("pause");
  17. return 0;
  18. }
  19.  
  20. int isVowel(char c) 
  21.    return strchr("aeiou", c) != NULL;// was null; 
Sep 10 '09 #11
phelle25
3 New Member
hi,
thank u very much for the time and suggestions. actually i got the answer now and i passed th assignment. here it is:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

bool isvowel(char var);

main(){
char v;
bool r;
printf("\n\n\tE nter a Letter: ");
scanf("%c",&v);
r = isvowel(v);

if(r == true) {printf("\nLett er %c is a vowel", v);}
else printf("\nLette r %c is not a vowel",v);

getche();


}

bool isvowel(char var){
bool e;

if(var=='a'||va r=='A'||var=='e '||var=='E'||va r=='i'||var=='I '||var=='o'||va r == 'O'||var=='u'|| var=='U')
{
e = true;
}
else e = false;

return e;


}

God bless
Sep 10 '09 #12
donbock
2,426 Recognized Expert Top Contributor
Good for you!

I hope you'll be patient with me for a few pedantic observations.
  1. Which of your headers defined the bool type?
  2. If you're not using C99 and <stdbool.h>, then it is advisable to avoid comparing a bool variable directly to true -- as in if(r == true). There is only one false value (0), but all nonzero values are true. Your variable might have a different nonzero value than "true". I would replace this line with either if(r) or if(r != false).
  3. Did you know you could replace the bulk of isvowel by return ((var=='a')||.. .||(var=='U'));? This construction is equivalent to your code.
  4. The C Standard mandates that main return an int. In fact, your main function has an implicit int return value. Explicit is usually better than implicit. Either way, you need a return statement at the end of main.
  5. Regarding the problem specification, should "Y" be considered a vowel? The vowel list I learned so many years ago was "A, E, I, O, U, and sometimes Y". If you're feeling whimsical, you could randomly choose between vowel or nonvowel if (and only if) the input character is "Y".

You have a working program, so don't change it. These observations are to help with your next project.

Cheers,
don
Sep 10 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2087
by: Bob | last post by:
Hi, I have a std::vector, say myVec, of some user defined object, say myOb. In my code, I have a function that searches myVec for a particular myOb. The way I was doing this was searching myVec for the element that has a member equal to a value that was passed into the function. For example:
18
1759
by: deanbrown3d | last post by:
I mean, is this correct? try { Screen->Cursor = crHourglass; Do something bad return false; else return true; }
8
1967
by: aundro | last post by:
Hello all, I was wondering whether I could do something like: --snip-- MyType.prototype.myProp = {var xxx = 'this is a string'; xxx.substring(4);} --snip--
1
2855
by: WLF | last post by:
I have the following function (C# behind aspx page): private void ButtonNewSupplier_Click(object sender, System.EventArgs e) { Response.Write("<script language=javascript>window.showModalDialog('" + Const.sPPAddSupplier + "','_blank','left=50,top=50,toolbar=false,status=yes,directories=false,menubar=false,scrollbars=true,copyhistory=false,width=500,height=500');</script>"); }
5
3966
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie Save should not happen) the js function is as function IsValidAmount() {
11
2771
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print "YAHHH" .... result =
9
6581
by: Water Cooler v2 | last post by:
Is it necessary to return a value from the event handlers? For instance, what does the return value in the following code signify? What will be its impact if it returned otherwise (true)? <a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver event'); return true"> <img src="Click.gif" width="100" height="30"> </a>
3
15431
by: Doug | last post by:
Hi i have a method that returns a value public bool readxml (string xmlFilename, out string value) but I would like to catch an exception if it occurs in the method . How do i catch the following error if the xmlField 'location' doesn't exist in the xmlfile or if the xmlfile is blank?
9
11190
by: Jamey Bon | last post by:
As a newbie to C#, I am not sure what I can do about this. I would like to do something like an Enumeration to use "constants" like Yes to indicate true and No for false. But since there seems to be no underlying 0 or non- zero for boolean values in C#, I am not sure how to handle this. Any advice would be appreciated. Thanks, JB
7
10323
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If lvServers.InvokeRequired = True Then lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.