Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- /**
- * Draws ASCII art square of given size with given char.
- *
- * @param size Size of square to be drawn
- * @param c Char to be used to draw a square..
- */
- void drawSquare ( int size, char c )
- {
- for ( int i = 0; i < size; ++i )
- for ( int j = 0; j < size; ++j )
- std::cout << c << ( j == size-1 ? "\n" : " " );
- }
- /**
- * Program capable of drawing simple ASCII square.
- *
- * @return Returns 1 if wrong input is detected, 0 if everything ok.
- * @author Michael Hartman [email protected]
- */
- int main ( int argc, char ** argv )
- {
- std::cout << "Enter number: ";
- int num;
- if ( ! ( std::cin >> num ) || num < 0 )
- {
- std::cerr << "Bad input!" << std::endl;
- return 1;
- }
- drawSquare ( num, '*' );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment