/* diamond.cpp - Matt Mahoney This program prompts the user for his/her name, then prints a greeting surrounded by a diamond of asterisks. For example: Please enter your first name: Matt * * * * * * * * * * * * * * * * Hello, Matt! * * * * * * * * * * * * * * * * The greeting is centered, moved 1/2 space left if needed. To compile: g++ diamond.cpp -o diamond */ #include #include using namespace std; int main() { // Prompt and construct greeting, pad to make its size odd cout << "Please enter your first name: "; string greeting; cin >> greeting; greeting = "Hello, " + greeting + "!"; if (int(greeting.size())%2 == 0) greeting += " "; // Print the greeting inside a diamond const int n = greeting.size()/2 + 2; // length of one side cout << string(n, ' ') << "*\n"; // top for (int i=1; i0; --i) // lower sides cout << string(n-i, ' ') << "*" << string(i*2-1, ' ') << "*\n"; cout << string(n, ' ') << "*\n"; // bottom return 0; }