Uppercase to Lowercase Conditional Operation

Desired Output:
Enter Line of strings: qwE
Given line of strings: qwE
Change strings: QWe

My output:
Enter Line of strings: qwE
Given line of strings: qwE
Change strings: QWE

Please help. Thank you.

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
  #include<iostream>
#include<cstring>
using namespace std;
char phrase[1000];
char ltr;


int main()
{
	cout << "Enter line of strings: ";
	cin.getline(phrase, 1000);

	cout << "Given line of strings: " << phrase;
	cout << "\nChange strings: ";
	for (int i = 0; i < strlen(phrase); i++)
		if (tolower){
		ltr = toupper(phrase[i]);
		cout << ltr;
		}
		else if (toupper){
			ltr = tolower(phrase[i]);
			cout << ltr;
		}

	system("pause>0");
	return 0;
}
I think you mean

line16:
 
if (islower())

and

line20:
 
if (isupper())
It errors...
Yes, because that's the template needed to do what you want to do. You should research those functions, and you will see the prototype needed.

Anyway:

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
#include<iostream>
#include<cstring>
using namespace std;
char phrase[1000];


int main()
{
	cout << "Enter line of strings: ";
	cin >> phrase;
	
	cout << "Given line of strings: " << phrase;
	cout << "\nChange strings: ";

	for (int i = 0; i < strlen(phrase); i++)
	{
		if (islower(phrase[i]))
		{
			phrase[i] = toupper(phrase[i]);
			cout << phrase[i];
		}

		else if (isupper(phrase[i]))
		{
			phrase[i] = tolower(phrase[i]);
			cout << phrase[i];
		}
	}
		system("pause");
		return 0;
}
Last edited on
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
#include<iostream>
#include<cstring>
using namespace std;
char phrase[1000];
char ltr;


int main()
{
	cout << "Enter line of strings: ";
	cin.getline(phrase, 1000);

	cout << "Given line of strings: " << phrase;
	cout << "\nChange strings: ";
	for (int i = 0; i < strlen(phrase); i++){
		if (islower){
			ltr = toupper(phrase[i]);
			cout << ltr;
		}
		else if (isupper){
			ltr = tolower(phrase[i]);
			cout << ltr;
		}
	}
	system("pause>0");
	return 0;
}

CODE UPDATED
omg thank you
You only need that one variable (phrase), and it's usually best practice (especially if you'rea beginner) to explicitly define your functions. i.e. Your for() loop did not have {} encompassing all the code. Also, you can fill the whole array of "phrase" just with cin. Bear in mind that cin reads until whitespace, so if you have multiple words, that method of getting the input will not work. Good luck.
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
#include<iostream>
#include<cstring>
using namespace std;
char phrase[1000];
char ltr;


int main()
{
	cout << "Enter line of strings: ";
	cin >> phrase;

	cout << "Given line of strings: " << phrase;
	cout << "\nChange strings: ";
	for (int i = 0; i < strlen(phrase); i++){
		if (islower(phrase[i])){
			ltr = toupper(phrase[i]);
			cout << ltr;
		}
		else if (isupper(phrase[i])){
			ltr = tolower(phrase[i]);
			cout << ltr;
		}
	}
	system("pause>0");
	return 0;
}
Last edited on
I fixed it. Thank you very much :)
Perfect, np :)
Topic archived. No new replies allowed.