I have created a function that draws a square based on user input.
Is there a better way or any ways I can make the code smaller but still work as
efficently?
Code:#include <iostream> using std::cout; using std::endl; using std::cin; // function prototype int draw ( int ); // main function - driver ////////////////////////////////////////////////////// // int main ( void ) { int n; cout << "Enter a side value: "; cin >> n; draw ( n ); cin.get(); // freeze console window cin.ignore(); return 0; // indicate program ended sucsessfuly } // function draws a square int draw ( int n ) { int counter = 0; do // makes sure the hieght is correct { for ( int i = 1; i <= n; i++ ) // deals with length { cout << "*"; } cout << "\n"; counter++; } while ( counter < n ); return n; }



LinkBack URL
About LinkBacks



[/edit]