#include using namespace std; // Making fence // Author : Chikashi KIMURA // 07/11/03 //Check the number of post (post>=2), positive length, and positive height. bool check(int post, int length, int height) { return (post >= 2 && length > 0 && height > 0); } // This function make Piece of fence depend on the length. void MakingPiece(int length) { while(length>0) // loop test { cout << "-"; // loop body length--; // update } } // This function make Fence while post>0 and make the last pole. void PrintFence(int post, int length) { while(post>1) // loop test { cout << "|"; // loop body MakingPiece(length); post--; // update } cout << "|" << endl; // making the last fence } // This function decide hieght of the fence void HieghtFence(int post, int length, int height) { while(height>0) // loop test { PrintFence(post, length); // loop body height--; // update } } int main() { int post; int length; int height; cout << "How many posts does fence have?" << endl; cin >> post; cout << "How long does the each cross-piece?" << endl; cin >> length; cout << "How height is this?" << endl; cin >> height; if (check(post, length, height)) { HieghtFence(post, length, height); } else { cout << "Invalid input!" << endl; } return 0; }