Question: I'm trying to get this code to work for C++ to print this program once you enter your first and last name, like this: A

I'm trying to get this code to work for C++ to print this program once you enter your first and last name, like this: A = hello,; B = first and last name printed once asked to enter. The A and B should be surrounded by the * in this format of the following. I don't know where to place the B statement and to write it and why it won't print below the A statement.

******

* *

* A *

* B *

* *

******

The code I have now is this:

#include #include

using std::cin; using std::cout; using std::endl; using std::string;

int main() { cout << "Please enter your first name: "; string firstname; cin >> firstname;

cout << "Please enter your last name: "; string lastname; cin >> lastname;

const string greeting = "Hello, "; const int pad = 1;

const int rows = pad * 2 + 3; const string::size_type cols = greeting.size() + pad * 2 + 2;

cout << endl;

for ( int r = 0; r != rows; ++r) { string::size_type c = 0;

while (c != cols) {

if ( r == pad + 1 && c == pad + 1) { cout << greeting; c += greeting.size();

} else {

if ( r ==0 || r == rows - 1 || c == 0 || c == cols - 1) cout << "*"; else cout << " "; ++c; } } cout << endl; } return 0; }

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!