Advice on making a hollow square with information inside

Hey guys. I know you get questions like these all the time and I tried to look through past posts but I cannot seem to find an example of a hollow square with a menu inside. I have tried many different things and think I need another persons look at it.
A hollow box of "stars" is supposed to surround the menu.
Any information is much appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 #include <iostream>
#include<iomanip>
using namespace std;
int main()
{
int quarter, dime, nickel, penny;
int choice;
float balance=0.0, remainder=0, withdraw=0, deposit=0;

	for(int i=0;i<35;i++)
		cout<<'*';
		for(int a=0;a<10;a++)
			{cout<<endl<<'*';


do
{
	cout<<setprecision(2)<<fixed;

	cout<<endl<<"*"<<setw(9)<<" "<<"Piggy Bank Menu"<<setw(9)<<" "<<"*"<<endl;
	cout<<endl<<"Current Balance $  "<<balance<<endl;
	cout<<endl<<"1)  Make Deposit"<<endl<<"2)  Make Withdraw"<<endl<<"3)  View Coins"<<endl<<"4)  Exit Program"<<endl;
	cout<<endl<<endl<<"Enter choice: ";
	cin>>choice;
	if (choice<0||choice>4)
		{cout<<"Invalid Option. Try Again";}


just keep it simple and do something like this.
1
2
3
4
5
6
		cout << "**********************************************************" << endl;
		cout << "*                     MAIN MENU                          *" << endl;
		cout << "*              1.  Enter a new person                    *" << endl;
		cout << "*              2.  Delete a person                       *" << endl;
		cout << "*                                                        *" << endl;
		cout << "**********************************************************" << endl;
I would love to do it like that. Unfortunately the professor emailed me back a few minutes ago and said he would like to see a nested for loop.
I'm not sure why you need nested loops for this. I wrote this up since you said you were looking for an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void printMenu(vector<string> &vec, unsigned int hpad, unsigned int vpad)
{
    unsigned int width = 0;

    //find out the length of the longest string
    for (vector<string>::iterator it = vec.begin(); it != vec.end(); ++it)
    {
        if (it->length() > width)
            width = it->length();
    }
    //add the horizontal padding
    width += hpad * 2;

    //print the top border
    cout << string(width + 2, '*') << endl;
    //print the vertical padding
    for (unsigned int i = 0; i < vpad; ++i)
        cout << '*' << string(width, ' ') << '*' << endl;
    //print the strings in the menu
    for (vector<string>::iterator it = vec.begin(); it != vec.end(); ++it)
    {
        unsigned int spaces = width - it->length();
        unsigned int before = spaces/2;
        unsigned int after = spaces - before;
        cout << '*' << string(before, ' ') << *it << string(after, ' ') << '*' << endl;
    }
    //print more vertical padding
    for (unsigned int i = 0; i < vpad; ++i)
        cout << '*' << string(width, ' ') << '*' << endl;
    //print the bottom border
    cout << string(width + 2, '*') << endl;
}

int main()
{
    vector<string> vstr;

    vstr.push_back("Piggy Bank Menu");
    vstr.push_back("Current Balance $1000");
    vstr.push_back("1) Make Deposit");
    vstr.push_back("2) Make Withdrawal");
    vstr.push_back("3) View Coins");
    vstr.push_back("4) Exit Program");

    printMenu(vstr, 4, 1);
    return 0;
}


If you were to use it, you would need to do some adjustments because currently it just centers every line. You'd also have to figure out how to put the current balance into a string.
Thank you. I am going to try and implement this into the program later today. I appreciate the help :)
Topic archived. No new replies allowed.