Guest User

Untitled

a guest
Oct 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. // Ask for a person's name, and generate a framed greeting
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. int main () {
  7.     std::cout << "Please enter your first name: ";
  8.     std::string name;
  9.     std::cin >> name;
  10.    
  11.     // build the message that we intend to write
  12.     const std::string greeting = "Hello, " + name + "!";
  13.    
  14.     // build the second and fourth lines of output
  15.     const std::string spaces (greeting.size(), ' ');
  16.     const std::string second = "* " + spaces + " *";
  17.    
  18.     // build the first and fifth line of output
  19.     const std::string first(second.size(), '*');
  20.    
  21.     // write everything
  22.     std::cout << std::endl;
  23.     std::cout << first << std::endl;
  24.     std::cout << second << std::endl;
  25.     std::cout << "* " << greeting << " *" << std::endl;
  26.     std::cout << second << std::endl;
  27.     std::cout << first << std::endl;
  28.     std::cin.get();
  29.     return 0;
  30.    
  31. }
Add Comment
Please, Sign In to add comment