I love this programme :P

#include <iostream>
#include <string>


using namespace std;

char lowerCase(char input0 = 0);
char upperCase(char input1 = 0);

int main()
{
	char character = 0;
	while(true)
	{

		cout << "Enter a Character to change case: ";
		cin >> character;
		cout << endl;
	if(character > 64 && character < 92)
	{
			cout << character << endl;
			cout << lowerCase(character) << endl;
	}
	else if (character > 96 && character < 123)
	{	
		
			cout << character << endl;
			cout << upperCase(character) << endl;
	}
	else{continue;}

	}
}


char lowerCase(char input0)
{	
	char j = 0;
	j = input0 + 32;
	return j;
}

char upperCase(char input1)
{
	char i = 0;
	i = input1 - 32;
	return i;
}

Recommended Answers

All 6 Replies

I love this programme :P

#include <iostream>
#include <string>


using namespace std;

char lowerCase(char input0 = 0);
char upperCase(char input1 = 0);

int main()
{
	char character = 0;
	while(true)
	{

		cout << "Enter a Character to change case: ";
		cin >> character;
		cout << endl;
	if(character > 64 && character < 92)
	{
			cout << character << endl;
			cout << lowerCase(character) << endl;
	}
	else if (character > 96 && character < 123)
	{	
		
			cout << character << endl;
			cout << upperCase(character) << endl;
	}
	else{continue;}

	}
}


char lowerCase(char input0)
{	
	char j = 0;
	j = input0 + 32;
	return j;
}

char upperCase(char input1)
{
	char i = 0;
	i = input1 - 32;
	return i;
}

good work, this is my version using the standard library.. is not better just different coding!

#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

int main()
{
	char c = 0;
	char b = 0;

	while(true)
	{
		cout << "Enter an alfabetic character to change case (ESC to exit) : ";
		cin >> c;
		cout << endl;

        // check for exit
		if(c == 27)
		{
		    cout << "Escape char!! exiting";

            return EXIT_SUCCESS;
		}

        // is a char ??
		if(!isalpha(c))
		{
            cout << c << " is not an alfabetic character, try again!" << endl << endl;
            continue;
		}

        // conversion
        if(isupper(c))
        {
            b = tolower(c);
            cout << c << endl << b ;
        }
        else if(islower(c))
        {
            b = toupper(c)
            cout << c << endl << b;
        }

        cout << endl;
    }

    return EXIT_SUCCESS;
}

You can make your code more readable by

if(c >= 'a' && c <= 'z')
{
//lower case
}
else if(c >= 'A' && c <= 'Z'
{
}

You can also do things like
char diff('A');
diff -= 'a';

to get the 32 number

To jBat and invisi I would reconsider your input methods. you are using cin >> val; which will cause an infinite loop to occur if if something other than a char is entered. I would suggest the use of get(cin, val); instead and then convert if necessary. here is a good link on this. http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.2

you are using cin >> val; which will cause an infinite loop to occur if if something other than a char is entered.

Other than a char ? Like what? If the input requires a char , what can you input that isn't a char ?

I'm sorry I didn't see the checks that were in place. My eyes were faster then my brains. This code is fine i though I saw something different.

I'm sorry I didn't see the checks that were in place. My eyes were faster then my brains. This code is fine i though I saw something different.

Been there, done that. Gonna do it again, too, unfortunately :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.