Nov 19, 2014 at 1:35am UTC
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 Nov 19, 2014 at 1:37am UTC
Nov 19, 2014 at 1:39am UTC
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.
Nov 19, 2014 at 1:39am UTC
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 Nov 19, 2014 at 1:40am UTC
Nov 19, 2014 at 1:41am UTC
I fixed it. Thank you very much :)