Question: My code isn't working properly. Here's question: C++ E4.15 Write a program to read a sequence of words and print them in a box with

My code isn't working properly. Here's question:

C++

E4.15 Write a program to read a sequence of words and print them in a box with each word centered, like:

+- - - - - - - -+

| Hello |

| C++ |

+ - - - - - - - -+

Here's my code:

#include

#include

using namespace std;

int main()

{

string s;

string word;

cout << "Enter String: " << endl;

cin >> word;

cout << ' ';

cout << "+--------+" << endl;

cout << "|" << word << "|" << endl;

cout << "+--------+" << endl;

return 0;

}

Problem:

When I enter string, cin >> cuts off rest of word. Also, string isn't centered like the question wants. What did I forget to add ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!