fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void print_board(int const width,
  7. int const height,
  8. char const char_1,
  9. char const char_2)
  10. {
  11. for (int i = 0; i < height + 1; i++) {
  12. for (int j = 0; j < width + 2; j++) {
  13. if (j == 0)
  14. cout << (i + 1) << " ";
  15. else {
  16. if (j % 2 == 0)
  17. cout << char_2;
  18. else
  19. cout << char_1;
  20. }
  21. }
  22. cout << endl;
  23.  
  24. if (i == height) {
  25. cout << " ";
  26. for (int k = 0; k < width + 1; k++) {
  27. cout << static_cast<char>('A' + k);
  28. }
  29. }
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. int width {};
  36. int height {};
  37. char char_1 {};
  38. char char_2 {};
  39.  
  40. cout << "Enter width and height: ";
  41. cin >> width >> height;
  42. cout << endl << "Enter characters: ";
  43. cin >> char_1 >> char_2;
  44. cout << endl;
  45.  
  46. print_board(width, height, char_1, char_2);
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 5556KB
stdin
3 7 / !
stdout
Enter width and height: 
Enter characters: 
1 /!/!
2 /!/!
3 /!/!
4 /!/!
5 /!/!
6 /!/!
7 /!/!
8 /!/!
  ABCD