checkerboard.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Programmer: Jonathan Landrum
  3. * Date: 24 February 2012
  4. *
  5. * Program: checkerboard.cpp
  6. * Purpose: Prints a checkerboard of
  7. * user-defined size.
  8. * Assumptions: None.
  9. *
  10. */
  11. #include <iostream>
  12. using namespace std;
  13. // --------------------------------------------------
  14. // main():
  15. // --------------------------------------------------
  16. int main () {
  17. // Variables
  18. int counter, iterator, input;
  19. // Introduce the program
  20. cout << endl;
  21. cout << "----------------------------------" << endl;
  22. cout << "- C++ Checkerboard Printer -" << endl;
  23. cout << "----------------------------------" << endl;
  24. cout << endl;
  25. cout << " +-----+" << endl;
  26. cout << " | |" << endl;
  27. cout << " | |" << endl;
  28. cout << " | |" << endl;
  29. cout << " +-----+" << endl;
  30. cout << endl;
  31. cout << "This program takes user input of an" << endl;
  32. cout << "integer and prints a checkerboard" << endl;
  33. cout << "of that size." << endl;
  34. cout << "What size checkerboard do you want: ";
  35. cin >> input;
  36. // Main processing loop
  37. for (counter = 0; counter < input; ++counter) {
  38. for (iterator = 0; iterator < input; ++iterator) {
  39. cout << "+-----";
  40. }
  41. cout << "+" << endl;
  42. for (iterator = 0; iterator < input; ++iterator) {
  43. cout << "| ";
  44. }
  45. cout << "|" << endl;
  46. for (iterator = 0; iterator < input; ++iterator) {
  47. cout << "| ";
  48. }
  49. cout << "|" << endl;
  50. for (iterator = 0; iterator < input; ++iterator) {
  51. cout << "| ";
  52. }
  53. cout << "|" << endl;
  54. } // End for
  55. for (iterator = 0; iterator < input; ++iterator) {
  56. cout << "+-----";
  57. }
  58. cout << "+" << endl;
  59. // Return the results
  60. return (0);
  61. } // End main