Problem with cctype family

Hello, I'm doing a program that reads keyboard input, converting each uppercase character to lowercase and viceversa. However, the code doesn't work. In my opinion, the problem is in the way that I used the cctype family.

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
#include "iostream"
#include "string"

int main()
{
	using namespace std;
	char ch;
	string ch2;
	string text;
	cin >> ch;

	while (ch != '@')
	{
		if (!isdigit(ch));
		{
			if (islower(ch))
				ch = toupper(ch);
			else
				ch = tolower(ch);
		}
		ch2 = ch;
		text.append(ch2);
		cin >> ch;
	}
	
	cout << text << endl;

	system("pause");
    return 0;
}


Thanks for your help.
Line 14 means nothing (notice the semicolon at the end). You can remove it.

cin >> ch is formatted input. You probably want unformatted input.

I'm not sure why you are terminating input at an at-sign; you could just terminate at EOF.

Use angle brackets for standard includes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

int main()
{
	using namespace std;
	char ch;
	string text;

	while (cin.get( ch ))
	{
		if (islower(ch))
			ch = toupper(ch);
		else
			ch = tolower(ch);

		text.append(1,ch);  // text += ch;
	}
	cout << text << "\n";
}

Hope this helps.
Topic archived. No new replies allowed.