Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::cin;
  6. using std::endl;
  7. using std::string;
  8.  
  9. int main()
  10. {
  11.  
  12. cout << "Pretty standard greeting program. Enter your name: ";
  13. string name;
  14. cin >> name;
  15. cout << endl;
  16. cout << "Enter amount of padding to use: ";
  17. int padinp;
  18. cin >> padinp;
  19. cout << endl;
  20.  
  21.  
  22. const string greeting = "Hello, " + name + "!";
  23. const int pad = padinp;
  24.  
  25. const int rows = pad * 2 + 3;
  26. const string::size_type cols = greeting.size() + pad * 2 + 2;
  27.  
  28. for(int r = 0; r != rows; ++r)
  29. {
  30. string::size_type c = 0;
  31.  
  32. while (c != cols)
  33. {
  34. if (r == pad + 1 && c == pad + 1)
  35. {
  36. cout << greeting;
  37. c+= greeting.size();
  38. }
  39. else
  40. {
  41. if ( r == 0 || r == rows - 1 || c == 0 || c == cols - 1)
  42. {
  43. cout << "*";
  44. }
  45. else
  46. {
  47. cout << " ";
  48. }
  49. ++c;
  50. }
  51. }
  52. cout << endl;
  53. }
  54. }
Add Comment
Please, Sign In to add comment