Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::cout;
- using std::cin;
- using std::endl;
- using std::string;
- int main()
- {
- cout << "Pretty standard greeting program. Enter your name: ";
- string name;
- cin >> name;
- cout << endl;
- cout << "Enter amount of padding to use: ";
- int padinp;
- cin >> padinp;
- cout << endl;
- const string greeting = "Hello, " + name + "!";
- const int pad = padinp;
- const int rows = pad * 2 + 3;
- const string::size_type cols = greeting.size() + pad * 2 + 2;
- 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;
- }
- }
Add Comment
Please, Sign In to add comment