Replacing capital letters with small lettes and small letters with capital letters.

This program replaces the small letter vowels with capital letters. How do I get it to replace small letters with capital letters (for all of the letters, not only the vowels.) ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{ char n[100];
  cout<<"Enter a line of text: ";
  cin.get(n,100);
  for(int i=0; n[i]!='\0'; i++)
{
   if(n[i]=='a')
   n[i]='A';
   else if (n[i]=='e')
   n[i]='E';
   else if (n[i]=='i')
   n[i]='I';
   else if (n[i]=='o')
   n[i]='O';
   else if (n[i]=='u')
   n[i]='U';
}
cout<<"The new text: "<<n;
return 0;
}
Hi, look at the functions isupper, toupper, islower, tolower.
^
Include the header file <cctype>.
It has library functions like tolower, toupper.
Also remember when you're inputting or outputting an array, you always have to do it in a loop since it contains more than 1 value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<cstring>
#include<cctype>
using namespace std;

int main()
{ 
char n[100]; // create a character array called "n" for 100 memory location

cout<<"Enter a line of text: ";
cin.get(n,100);

for(int i=0; n[i]!='\0'; i++)
{
   n[i] = toupper(n[i]); // turns everything it reads in to uppercase
}

cout<<"The new text: "<< endl;
for (int i = 0; n[i] != '\0'; i++)
{
cout<<n[i] << endl;
}
return 0;
}
Topic archived. No new replies allowed.