Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- /**
- * Draws ASCII plus sign of given size from given char.
- *
- * @param size Size of the plus sign to be drawn.
- * @param c Char to use for plus sign drawing.
- */
- void drawPlus ( int size, char c )
- {
- for ( int i = 0; i < size; ++i ) // loop for columns
- {
- for ( int j = 0; j < size; ++j ) // loop for rows
- {
- if ( i == size / 2 ) // do not print anything in the middle row as it is special
- continue;
- if ( j == size / 2 )
- std::cout << c << " ";
- else
- std::cout << " ";
- }
- if ( i == size / 2 ) // special middle row
- {
- for ( int k = 0; k < size; ++k )
- std::cout << c << " ";
- std::cout << std::endl << std::endl;
- }
- else
- std::cout << std::endl << std::endl;
- }
- }
- /**
- * Program reads one odd number from user and then prints ASCII plus sign.
- *
- * @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 odd number: ";
- int num;
- if ( ! ( std::cin >> num ) || ! ( num % 2 ) || num < 0 )
- {
- std::cerr << "Wrong input!" << std::endl;
- return 1;
- }
- drawPlus( num, '*' );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment