Almost there!

Hi All!

I have been working on a program for class that compares to characters together. I have written the program but it always returns the values as true even though they are not true. I am not understanding where I am going wrong, can I please get a push in the right direction! Thank you so much for your time and help


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>

using namespace std;
using namespace toupper;

void getInputChar(string, char &);
bool ignoreCaseCompare(char, char);


int main()
{
    string prompt = "Enter a character ";
    char c1, c2;

	bool equal;

    getInputChar(prompt, c1);
    getInputChar(prompt, c2);

    equal = ignoreCaseCompare(c1, c2);

	if(equal == true)
	{

	cout << c1 << " and " << c2 << " are equal!!" <<endl;
	cout << "Great Job! " <<endl;
	}

	else
	{
		cout << "......yea..." << c1 << " and " << c2 << " are not the same......" <<endl;
		cout << "....." << endl;
		cout << "dumb ass" << endl;
	}

    system ("pause");
    return 0;
}

 bool ignoreCaseCompare(char c1, char c2)
 {
 	c1 = toupper(c1);
	c2 = toupper(c2);
	return c1, c2;
 }

void getInputChar(string msg, char &cha)
{
	cout << msg;
	cin >> cha;
}


Thank you ahead of time for your help!
This function does not return if c1 equals c2.
1
2
3
4
5
6
 bool ignoreCaseCompare(char c1, char c2)
 {
 	c1 = toupper(c1);
	c2 = toupper(c2);
	return c1, c2;
 }


In your case, c1 will be returned as a bool, and c2 discarded.
Edit: I lied. It's the other way around, from what I tested.

return c1 == c2;
This will return true if they're equal, and false otherwise.
Last edited on
There is no such namespace as toupper in your program so remove the statement

using namespace toupper;

It si better to declare function getInputChar as

1
2
3
4
5
6
7
bool getInputChar( const std::string &msg, char &ch )
{
	std::cout << msg;
	std::cin >> ch;

	return ( std::cin );
}


Function ignoreCaseCompare contains an invvalid return statement. Shall be

1
2
3
4
5
6
7
 bool ignoreCaseCompare(char c1, char c2)
 {
 	c1 = toupper( c1 );
	c2 = toupper( c2 );

	return ( c1 == c2 );
 }


The following statements

1
2
3
4
5
6
	bool equal;


    equal = ignoreCaseCompare(c1, c2);

	if(equal == true)


could be replaced with one sttatement

if ( ignoreCaseCompare(c1, c2) )
Ok thank you for your help, I am glad I was not to far off.
Topic archived. No new replies allowed.