michael_hartman_cz

PedF UK - OKB1319205 Ukol1b

May 21st, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  /**
  4.   * Draws ASCII art triangle of given size with given char.
  5.   *
  6.   * @param size Size of triangle to be drawn
  7.   * @param c Char to be used to draw a triangle.
  8.   */
  9.  
  10. void drawTriangle ( int size, char c )
  11.  {
  12.     for ( int i = 0; i < size; ++i )
  13.         for ( int j = 0; j <= i; ++j )
  14.             std::cout << c << ( j == i ? "\n" : " " );
  15.  }
  16.  
  17.  /**
  18.   * Program capable of drawing simple ASCII triangle.
  19.   *
  20.   * @return Returns 1 if wrong input is detected, 0 if everything ok.
  21.   * @author Michael Hartman [email protected]
  22.   */
  23.  
  24. int main ( int argc, char ** argv )
  25.  {
  26.     std::cout << "Enter number: ";
  27.     int num;
  28.     if ( ! ( std::cin >> num ) || num < 0 )
  29.      {
  30.         std::cerr << "Bad input!" << std::endl;
  31.         return 1;
  32.      }
  33.    
  34.     drawTriangle ( num, '*' );
  35.     return 0;
  36.  }
Advertisement
Add Comment
Please, Sign In to add comment