fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. // Function to print the envelope with the messages inside
  5. void printEnvelope(const std::string& message1, const std::string& message2) {
  6. int width = 40; // Envelope width
  7. int height = 12; // Envelope height
  8.  
  9. // Draw the top of the envelope
  10. for (int i = 0; i < width; i++) {
  11. std::cout << "-";
  12. }
  13. std::cout << std::endl;
  14.  
  15. // Draw the sides of the envelope with space in between
  16. for (int i = 0; i < height - 4; i++) {
  17. std::cout << "|";
  18. for (int j = 0; j < width - 2; j++) {
  19. std::cout << " ";
  20. }
  21. std::cout << "|" << std::endl;
  22. }
  23.  
  24. // Draw the first message inside the envelope
  25. std::cout << "|";
  26. int padding1 = (width - 2 - message1.length()) / 2;
  27. for (int i = 0; i < padding1; i++) {
  28. std::cout << " ";
  29. }
  30. std::cout << message1;
  31. for (int i = 0; i < (width - 2 - message1.length()) - padding1; i++) {
  32. std::cout << " ";
  33. }
  34. std::cout << "|" << std::endl;
  35.  
  36. // Draw the second message inside the envelope
  37. std::cout << "|";
  38. int padding2 = (width - 2 - message2.length()) / 2;
  39. for (int i = 0; i < padding2; i++) {
  40. std::cout << " ";
  41. }
  42. std::cout << message2;
  43. for (int i = 0; i < (width - 2 - message2.length()) - padding2; i++) {
  44. std::cout << " ";
  45. }
  46. std::cout << "|" << std::endl;
  47.  
  48. // Draw the bottom of the envelope
  49. for (int i = 0; i < width; i++) {
  50. std::cout << "-";
  51. }
  52. std::cout << std::endl;
  53. }
  54.  
  55. int main() {
  56. // Define the two messages
  57. std::string message1 = "I miss you Batouty";
  58. std::string message2 = "Love you Habeeby";
  59.  
  60. // Call the function to print the envelope with the messages
  61. printEnvelope(message1, message2);
  62.  
  63. return 0;
  64. }
  65.  
Success #stdin #stdout 0.01s 5284KB
stdin
 
stdout
----------------------------------------
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
|                                      |
|          I miss you Batouty          |
|           Love you Habeeby           |
----------------------------------------