I have this program that works by asking the user to determine what size box they would like displayed. It asks 7 times.
What I need to do is modify it so it just prints the output without asking the user. (that's what happens when you don't read the assignment thoroughly!)
The output should say:
A box of 3 is shown below:
* * *
* * * (without the * in the middle)
* * *
It;s supposed to display boxes sized 5, 4, 3, 2, 1, then error messages for 0 and -1.
I got the code working but now I don't know how to change it to just display everything without asking the user to specify the size.
sorry if this is hard to read...everything moved when I pasted it.Code:#include <iostream> #include <cmath> using namespace std; int centspace(); int counter(); //Functions used ... void instructions (); //User instructions int box (); //------------------------------------------------------- int main () { instructions (); box (); box (); box (); box (); box (); box (); box (); cout << endl; return 0; } //-------------------------------------------------- int box () { int size; cout << "enter a number: "; cin >> size; if ((size <= 0) || (size >= 40)) { cout << "It is not possible to print a box of size " << size << endl; } else { for (int counter = 1; counter <= size; counter++) cout << "* "; cout << endl; if (size > 2) { for (int counter = 1; counter <= (size-2); counter++) { cout << "*"; for (int space = 1; space <= (size-2); space++) cout << " "; cout << " *" << endl; } } if (size > 1) { for (int counter = 1; counter <= size; counter++) { cout << "* "; } cout << endl; } } return 0; }
Any point in the right direction would help me tremendously. Thanks!