Anyone good with C++ programming stuff NEED HELP D;

Looking for a good c++ programmer to help assist with the following. I just need help with PART D thats all im askin. I seem to struggle with it. Thanks for whoever really helped!







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.
For each line there should be a beginning '*' and at the end of each line there should be a constant number of total characters so you may need to add some spaces to lines shorter than the longest line and terminate each line with a closing '*'. If we assume a rectangle of *'s is what is desired and not actual equal height and width lines. Ask your instructor to clarify.

To generalize this as much as possible you should create a function which loops through each string which would be displayed(without actually displaying it) to find the longest line first and save that number to a integer. Then in the code block that actually displays the menu;
Output a '*'
Output the menu string.
Output a number of spaces equal to the longest line+1 minus the current line length.
Output a '*' and a line break.

Note: the font of the terminal may not have a constant spacing per character. And i do not know of a function for a program to query its standard out for font type, perhaps google will help you there. Or perhaps your instructor assumes the standard out will have constant spacing, ask him.
For years i searched for deep truths. A thousand revelations. At the very edge...the ability to think itself dissolves away.Thinking in human language is the problem. Any separation from 'the whole truth' is incomplete.My incomplete concepts may add to your 'whole truth', accept it or think about it
Last edited by SkyCore on Sep 15, 2015, 2:51:49 AM
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

int main()
{
int number;
string name;
char c2;
cout << "Which number should be used for the menu border?";
cin >> c2;
cout << "What name should be used to Welcome the user?";
name = 'Lily';
cin >> name;
cout << 'a' << left << setfill('a') << setw(51) << 'a' << 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" << endl;
cout << 'a' << '\n' << 'a' << '\n' << 'a' << '\n' << 'a' << '\n' << 'a' << '\n';
cout << 'a' << left << setfill('a') << setw(54) << c2 << 'a' << endl;
cout << "Which menu number choice you chose?";
cin >> number;
number = 1;
cout << "You have chosen a " << number << endl;
return 0;
}







this is my code and it comes out like this:

http://imgur.com/srEurY6




And my questions is: How do i make the "a's" fill up in the left side to make it look like a rectangle like you said and do the same thing to the other side.

If i keep doing cout << 'a' <, endl; until it fills it will look like this

http://imgur.com/cB8Dydv

then it is going to keep bringing whatever is inside the a's down

What i want is to fill the a's around the text inside like a rectangle without bringing whatever is inside down.

Thanks for assisting me!
Last edited by uoweme6 on Sep 14, 2015, 9:24:13 PM
First off, you are using 'a' where i think you meant to instead use the variable c2.

Secondly you forgot to welcome your user.

*ignore this paragraph* After each /n or endl (new line) you want to output c2 to get c2 to be up/down on the left side of the screen. To get the up/down line on the right side you will need to output c2 immediately before each new line. But that may not display as a straight line because each of the lines may be of a different length. *ignore this paragraph*

But after examining your code i notice you are using stream justification with setw(using the <iomanip> library). So i believe what your instructor is looking for is to set it left, output stuff, then set it right and outputting c2 for the rightmost border. For each line.

You can accomplish the same results in programming through totally different code.


For years i searched for deep truths. A thousand revelations. At the very edge...the ability to think itself dissolves away.Thinking in human language is the problem. Any separation from 'the whole truth' is incomplete.My incomplete concepts may add to your 'whole truth', accept it or think about it
Last edited by SkyCore on Sep 14, 2015, 11:21:32 PM
I highly recommend creating an integer constant to represent the width of your menu and using that constant to size each line of the menu. This way, you can easily change the width of the menu in one place. Also, the constant can help for code readability.

Regarding the left/right border characters, I recommend looking into the string::resize(int) function. You can use this function to grow or shrink strings to desired lengths. After resizing strings, you can concatenate border characters to the front and back of them to obtain fitted menu strings.

If your menu is 54 characters wide and 2 characters are left/right border characters, then that leaves 52 characters which need to be filled per line.

1. Take potential menu line string X. (ex. "Welcome, Bob!")
2. Resize X to 52 characters. ("Welcome, Bob!" gets right padded with a bunch of whitespace)
3. Concatenate (borderCharacter + X + borderCharacter). (you now have a finished menu line)
4. Output menu line.

Repeat for each menu line, less the top and bottom borders.

Obviously, there are many ways to solve this problem!
Hopefully, my approach can help you a bit!
TY to those who called me out on my BS on these forums. There is no benefit to being so selfish as to fail to acknowledge others' differing beliefs of what "should be" or believe your own opinions so supreme as to be factual and thus dismiss others' opinions as being somehow a lie or delusional.

Report Forum Post

Report Account:

Report Type

Additional Info