Answer to Question #270987 in C++ for Nice

Question #270987

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


1
Expert's answer
2021-11-24T14:09:59-0500


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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS