Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions