Write a program that prompts the user to input a string and outputs the string in uppercase letters. You must use a
character array to store the string.
Sample program:
Enter a string: hello world!, welcome to programming
HELLO WORLD!, WELCOME TO PROGRAMMING
SOLUTION
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[20];
char upper_str[20];
cout << "Enter a string: ";
cin >> str;
cout << "The string you entered is: " << str << endl;
//Now let us convert to uppercase
for(int i = 0; i < 20; i++)
{
char ch = str[i];
if(ch!=" ")
{
upper_str[i] = toupper(ch);
}
}
//print the uppercase string
cout << "The uppercase string is: " <<upper_str<<endl;
return 0;
}
Comments
Leave a comment