473,803 Members | 3,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Value Return Function that produces a true/false

13 New Member
I am at the end of my first semester of C++, and I'm not sure what I should do to make this program meet the requested specifications. The assignment is as follows:

Write a function called ignoreCaseCompa re() that has two character (char) parameters. The function should return true if the two characters received represent the same letter, even if the case does not agree. Otherwise, the function should return false. Then, write a simple main() function that uses your ignoreCaseCompa re().

Additional instructions:

Here is the function heading:
bool ignoreCaseCompa re(char c1, char c2)

{

//Write the code to compare c1 with c2 and return true/false

}


Here is what I have:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. //function prototype
  8. bool ignoreCaseCompare (char first, char second);
  9.  
  10. int main ()
  11. {
  12.     char first = ' ';
  13.     char second = ' ';
  14.  
  15.     cout << "Enter a letter: ";
  16.     cin >> first;
  17.     cout << "Enter another letter: ";
  18.     cin >> second;
  19.  
  20.     first = toupper(first);
  21.     second = toupper(second);
  22.  
  23.     cout << "Are the letters the same? " <<
  24.  
  25.     return 0;
  26. }
  27. //******function defintions*****
  28. bool ignoreCaseCompare (char one, char two)
  29.  
  30. {if (one == two)
  31. return true;
  32. else
  33. return false;
  34. }
  35.  
  36.     //end main function

This programs is much easier without the value-return function. Can anyone offer any advice or direction?
Mar 29 '10
33 11095
Frinavale
9,735 Recognized Expert Moderator Expert
Banfa, what is a "iomanipiulator "????
Mar 30 '10 #21
Frinavale
9,735 Recognized Expert Moderator Expert
No, no, no absolutely never ever ever never ever never ever (getting the picture?) should main return void.
In school I was fist taught that main should be void....I'm pretty sure of that. It wasn't until I started doing bash scripting did I see why the main function should return something and so I started implementing the main method so that it returned an int.
Mar 30 '10 #22
Banfa
9,065 Recognized Expert Moderator Expert
Opps, I mean iomanipulator they are the things, like boolalpha that you can pass to cout to perform all the formating you used to do with the codes in the printf % formats. Defined in the header <iomanip>.

For instance
Set text or numerical display of bool
Set field widths with left or right alignment
Set precision
Set display format of floating points
Set base to display integers
Set the field padding character

Here's the reference
Mar 30 '10 #23
Banfa
9,065 Recognized Expert Moderator Expert
In school I was fist taught that main should be void....
Yes it is unfortunate the some schools did, and still do, teach main returning void for C/C++ programming. It doesn't change the fact it is just about as wrong as you can get.
Mar 30 '10 #24
Frinavale
9,735 Recognized Expert Moderator Expert
Thanks for the reference (link seems to be down though or I just can't access it due to network stuffs).


At least now I know what you're talking about :)
Mar 30 '10 #25
Banfa
9,065 Recognized Expert Moderator Expert
The link is working for me.
Mar 30 '10 #26
zamaam0728
13 New Member
I'm still working on this. I feel like such a numbskull because it's still not right, and I have to make a change to this program for the next assignment.

Here are the changes I have made per your advice:
Expand|Select|Wrap|Line Numbers
  1. isSameCharacter = ignoreCaseCompare (first, second);
  2.     cout << "The two letters are the same: " << isSameCharacter?"true":"false" << endl;
  3.     return 0;
  4.     // end of main function
  5. }
  6. //****function defintions*****
  7. bool ignoreCaseCompare (char a, char b)
  8. {
  9.     bool isSameCharacter = false;
  10.     {
  11.         if (toupper (a)== toupper (b))
  12.         isSameCharacter = true;
  13.         else
  14.         isSameCharacter = false;
  15.     }
  16.  
  17.         return isSameCharacter;
  18.  
  19. }
Error messages:
error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload
Apr 5 '10 #27
donbock
2,426 Recognized Expert Top Contributor
To use CODE tags ...
  • Select [highlight] the source code in your post.
  • Click on the "#" button on the message toolbar.

Can't tell from your snippet:
  • What type is variable isSameCharacter?
  • What type is variable first?
  • What type is variable second?
  • What is the function prototype for ignoreCaseCompa re?

Usually error messages from the compiler identify the line of source code they are complaining about. That information is always helpful in interpreting the error message. Please tell us which source line the error messages refer to.
Apr 5 '10 #28
zamaam0728
13 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. //function prototype
  8. bool ignoreCaseCompare(char, char);
  9.  
  10. int main ()
  11. {
  12.     char first = ' ';
  13.     char second = ' ';
  14.     char ansTrueFalse = ' ';
  15.  
  16.     cout << "Enter a letter: ";
  17.     cin >> first;
  18.     cout << "Enter a second letter: ";
  19.     cin >> second;
  20.  
  21.     ansTrueFalse = ignoreCaseCompare (first, second);
  22.     cout << "The two letters are the same: " << ansTrueFalse?"true":"false" << endl;
  23.     return 0;
  24.     // end of main function
  25. }
  26. //****function defintions*****
  27. bool ignoreCaseCompare (char a, char b)
  28. {
  29.     bool ansTrueFalse = false;
  30.     {
  31.         if (toupper (a)== toupper (b))
  32.         ansTrueFalse = true;
  33.         else
  34.         ansTrueFalse = false;
  35.     }
  36.  
  37.         return ansTrueFalse;
  38.  
  39. }
  40.  
  41. //end of isSameCharacter 
errors are referencing line 22
Apr 5 '10 #29
donbock
2,426 Recognized Expert Top Contributor
Lines 8, 14, and 21 are inconsistent. What is the return type of ignoreCaseCompa re and why aren't you using that type?

What do you expect line 22 to do?
There are three double-quotes in line 22 -- sounds unbalanced.
What is that question mark supposed to do in line 22?
Apr 5 '10 #30

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

Similar topics

1
14158
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10." The PERL code is as follows:
4
16298
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or cancel), i go to 'webpage.htm' <body>
16
11501
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not an object... the function is like so: function calc_total() { var x,i,base,margin,total,newmargin,newtotal; base = document.frmKitAmount.txtTotalKitValue.value; margin = document.frmKitAmount.margin.value/100;
13
6208
by: Clevo | last post by:
Hello, I want to check if user select one from the radiobox group. How can I get the radiobox actual value in javascript. In the value field I see the default value, but how can I know if it really was selected? Thanks! <input name="menu_order" id = "menu_order1" type="radio" value="1">one<br> <input name="menu_order" id = "menu_order2" type="radio" value="2">two<br>
21
3995
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
9
2937
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval ("document.forms."+rowString+".value")) == true ) { //this alert works if the value is a letter,i.e,"a" alert("You have entered an non-numeric value.\nEnter a number in the appropriate box.");
3
4211
by: Allerdyce.John | last post by:
Hi, In my code, I have a function which has a return value in the declaration: bool myFunction( int a) { // my implmentation }
7
3248
by: turtle | last post by:
I want to find out the max value of a field on a report if the field is not hidden. I have formatting on the report and if the field doesn't meet a certain criteria then it is hidden. I want to get a max of the field for the ones that are not hidden. is this possible? TIA, KO
7
10329
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),...
2
4680
by: mndprasad | last post by:
Hi friends, Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice versa. I have implemented successfully for one text box, but it's done for the other field, since am getting script errors. <script> var queryField; var lookupURL; var divName;
0
9704
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
9569
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
10558
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
10318
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
10069
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
9130
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
5503
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
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.