//ask for a person's name, and greet the person
#include<iostream>
#include<string>
using std::cin;
using std::cout;
int main(){
/*std::cout << "Please enter your name: ";
std::string name;
std::cin >> name;
//build the message that we intend to write
const std::string greeting = "Hello, " + name + "!";
//build the second and fourth lines of the output
const std::string spaces(greeting.size(), ' ');
const std::string second = "* " + spaces + " *";
//build the first and fifth lines of the output
const std::string first(second.size(), '%');
//write it all
std::cout << std::endl;
std::cout << first << std::endl;
std::cout << second << std::endl;
std::cout << "* "<< greeting<< " *"<< std::endl;
std::cout << second << std::endl;
std::cout << first << std::endl;
{{
const std::string hello = "Hello";
const std::string message = hello + ",World" + "!"
};} //why this compiles i have no idea
return 0; */
//ask for the person's name
std::cout<< "please enter your first name: ";
//read the name
std::string name;
std::cin >> name;
//build the message that we intend to write
const std::string greeting = "Hello. " + name + "!";
//the number of blanks surrounding the greeting
const int pad = 1;
//the number of rows and columns to write
const int rows = pad * 2 + 3;
const std::string::size_type cols = greeting.size() + pad *2 + 2;
//write a blank line to separate the output from the input
cout << std::endl;
//write rows rows of output
//invariant: we have written r rows so far
for (int r=0; r != rows ; ++r){
std::string::size_type c = 0;
//invariant: we have written c characters so far in the current row
while(c != cols){
//is it time to write the greeting?
if(r == pad + 1 && c==pad +1){
cout << greeting;
c += greeting.size();
}else {
//are we on the border?
if (r == 0 || c ==0 || r == rows-1 || c == cols-1)
cout << "*";
else
cout << " ";
++c;
}
}
return 0;
}
}