How to do this program?

I need help with part d of this lab i have to do. I have tried a lot of ways but cant find a way to work it out. Any help is appreciated!i already did all except part D. Im going to copy and paste what i've done so far. So please assist me with part D! Thanks!




I. Write a C++ program that prints out the following menu for a game:


***************************************************
Welcome!

Please choose a number from the following options:

1. Play the game!
2. Demo the game!
3. Exit


****************************************************



II. Modify your program from Part I, in the following way.

A. Instead of simply having the message Welcome!, have the welcome message use the user’s name. Prompt the user for a name and then have a personalized welcome message. IF the user inputs the name Sue, the welcome message might say, “Welcome, Sue!”

B. Allow the user to personalize the look of the menu. Before you print out the menu, prompt the user for a character to be used for the menu border. Then, use that character instead of the asterisk (*) so that the menu is personalized.

C. Instead of ending the program with the final line of asterisks print a message to the user stating which menu number choice he/she has chosen. For example, if the user inputs a 1, a message should be printed.
You have chosen a 1.
D. Complete the border of the menu so that it forms a square around the banner instead of just a line above and below.


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

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
	int number;
	char c2;
	c2 = 'a';
	cout << "Which number should be used for the menu border?";
	cin >> c2;
	cout << "What name should be used to Welcome the user?";
	cin >> name;
	cout << left << setfill('a') << setw(80) << c2 << endl;
	cout << "\n  Please choose a number from the following options:" << endl;
	cout << "\t\n\n\t1.    Play the game!" << endl;
	cout << "\t2.    Demo the game!" << endl;
	cout << "\t3.    Exit.\n\n\n" << endl;
	cout << 'a' << left << setfill('a') << setw(79) << c2 << endl;
	cout << "Which menu number choice you chose?";
	cin >> number;
	number = 1;
	cout << "You have chosen a " << number << endl;
	return 0;
}
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
#include <iostream>

int main()
{
    // raw string literal
    // http://www.stroustrup.com/C++11FAQ.html#raw-strings
    char menu_string[] = R"(
*******************************************************
*                    Welcome!                         *
*                                                     *
* Please choose a number from the following options:  *
*                                                     *
* 1. Play the game!                                   *
* 2. Demo the game!                                   *
* 3. Exit                                             *
*                                                     *
*******************************************************)" ;

    std::cout << "character to be used for the menu border? " ;
    char border_character ;
    std::cin >> border_character ;
    
    // http://www.stroustrup.com/C++11FAQ.html#for
    for( char& c : menu_string ) // for each character in menu_string 
        if( c == '*' ) // if it is an asterisk
            c = border_character ; // replace it with the new border_character
    
    std::cout << menu_string << '\n' ; // print the modified menu
}

http://coliru.stacked-crooked.com/a/c91f99d77e80c8b8
im still confused since i just started c++ and its really stressfull ugh..

can you show the code applied to mine so i can figure out what i did wrong.
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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
    char border_char;
    cout << "Which character should be used for the menu border? ";
    cin >> border_char ;

    string name ;
    cout << "What is your name? ";
    cin >> name;

    const int WIDTH = 40 ;

    cout << '\n'
         << setfill(border_char) << setw(WIDTH) << right << border_char << '\n'
         << border_char << setfill(' ') << setw(WIDTH-1) << border_char << '\n'
         << border_char << ' ' << left << setw(WIDTH-3) << "      Welcome " + name + '!' << border_char << '\n'
         << border_char << setfill(' ') << setw(WIDTH-1) << right << border_char << '\n'
         << border_char << ' ' << left << setw(WIDTH-3) << "1. Play the game" << border_char << '\n'
         << border_char << ' ' << left << setw(WIDTH-3) << "2. Demo the game" << border_char << '\n'
         << border_char << ' ' << left << setw(WIDTH-3) << "3. Exit" << border_char << '\n'
         << border_char << setfill(' ') << setw(WIDTH-1) << right << border_char << '\n'
         << setfill(border_char) << setw(WIDTH) << right << border_char << "\n\n"
         << "enter your choice (1/2/3): " ;

    int choice ;
    cin >> choice ;
    cout << "\nyou have chosen " << choice << '\n' ;
}

http://coliru.stacked-crooked.com/a/99da9ca9e5a472da
i coudn't thank you enough ^_^ really thanks and sorry to bother you
Topic archived. No new replies allowed.