(Square of Any Character) Modify the function created in Exercise 6.22 to form the square out of whatever character is contained in character parameter fillCharacter. Thus, if side is 5 and fillCharacter is #, then this function should print the following:
#####
#####
#####
#####
#####
Solution:
#####
#####
#####
#####
#####
Solution:
#include <iostream> using std::cout; using std::cin; using std::endl; void square (int, char); int main() { int side; char fillCharacter; cout << "Enter side: "; cin >> side; cout << "Enter character: "; cin >> fillCharacter; square( side, fillCharacter ); return 0; } //square function void square( int side, char fillCharacter ) { for( int i = 1; i <= side; i++ ) { for( int j = 1; j <= side; j++) { cout << fillCharacter; } cout << endl; } }
Post A Comment:
0 comments: