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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started