473,698 Members | 2,616 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 #1
12 10264
JosAH
11,448 Recognized Expert MVP
I'd do it like this:

Expand|Select|Wrap|Line Numbers
  1. int isVowel(char c) {
  2.    return strchr("aeiou", c) != null;
  3. }
  4.  
For an explanation read this link.

kind regards,

Jos
Aug 31 '09 #2
donbock
2,426 Recognized Expert Top Contributor
@phelle25
Pull lines 12-23 into a separate function called something like LetterIsVowel. This new function accepts a single input argument (the letter to be tested) and provides an integer output, where 1 means true and 0 means false. Replace the printf statements with return statements. Then modify main to use this new function. Have main print either "true" or "false" based on the return value.

By the way, it helps if you use CODE tags for source code snippets.
Aug 31 '09 #3
phelle25
3 New Member
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#define vowels "aeiou"



main ()
{
char isvowel(char vowels);

char letter;
char letter1;
char ans;


do
{
printf("\n\nwan t to enter another letter(1=yes,0= No)?");
scanf("%d",&ans );
if (ans==1)
printf("\nEnter letter:");
scanf("%c",&let ter);
letter1=isvowel (letter);
printf("\nlette r is: %c",letter1);
}
while (ans==1);
}
char isvowel(char vowels)
{
char letter2;

if (letter2 == 'a'){

return ('T');}


else if (letter2 == 'e'){

return ('T');}


else if (letter2 == 'i'){

return ('T');
}

else if (letter2 == 'o'){

return ('T');
}

else if (letter2 == 'u'){

return ('T');






}
else
{
return ('F');
}

}
this is my return statement. but still something is wrong in the part char isvowel(char vowels); can u help me with this.
Sep 1 '09 #4
JosAH
11,448 Recognized Expert MVP
Have you read (and understood) my reply #2?

kind regards,

Jos
Sep 1 '09 #5
donbock
2,426 Recognized Expert Top Contributor
@phelle25
What do you pass as an argument when you call isvowel?
What is the argument used for in the definition of function isvowel?

Please use CODE tags! Compare the appearance of the source code in post #1 to the same code in post #3.
Sep 1 '09 #6
whodgson
542 Contributor
Have you you given any thought to using 'switch (char)' and 'case' where the cases would be each vowel (e.g case: 'a') and would print "true". The default case would print"not a vowel"or "false".
Sep 2 '09 #7
JosAH
11,448 Recognized Expert MVP
@whodgson
Why is everybody ignoring my reply #2?

kind regards,

Jos ;-)
Sep 2 '09 #8
donbock
2,426 Recognized Expert Top Contributor
@JosAH
I stand in awe as I gape agog at reply #2. ;-}

Seriously, my interpretation of the OP's messages is that the fundamental issue is how to write a function and how to invoke it. Making isvowel more efficient is beside the point.

The OP has bigger fish to fry so I wasn't going to bother him with this ... but I can't hold it in any longer. The C Standard reserves certain name patterns for possible use by future versions of the Standard. One of those reserved patterns is the regular expression "^is[a-z]" -- that is, a name that starts with "is" followed by a lowercase letter. The name "isvowel" impinges on this reserved pattern. The OP need not worry about changing the function name; this is not a program that will be used for years and years. Its when you write software that will be maintained for 10+ years that you are advised to be careful of these reserved name patterns.
Sep 2 '09 #9
JosAH
11,448 Recognized Expert MVP
@donbock
That's why I wrote isVowel( ... ) with an uppercase V, just to be safe ;-)

kind regards,

Jos
Sep 2 '09 #10

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

Similar topics

5
2084
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
1753
by: deanbrown3d | last post by:
I mean, is this correct? try { Screen->Cursor = crHourglass; Do something bad return false; else return true; }
8
1966
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
2850
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
3962
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
2767
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
6576
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
15428
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
11184
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
10317
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
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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
8873
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
7740
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...
0
5862
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
4372
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.