Having trouble with this code

Here is the screenshot: https://www.chegg.com/homework-help/questions-and-answers/c-problem-arrays-multidimensional-question-force-user-populate-entire-array-provide-option-q29294288

C++ Problem (Arrays: NOT MULTIDIMENSIONAL)

Question; Do not force the user to populate the entire array. PRovide them with the option of entering only as many elements as they want. In other words, if the array declared is of size 100, do not force them to enter 100 elements, provide a means to let them enter as many (or as few) as they want. Hint: You can either ask them in advance how many elements they want to enter or use a delimiter to signal the end of input (e.g. -9999).

Note that although this does not change the physical size of the array, all the operations performed henceforth should only be on the actual number of elements in the array. In other words, if only 5 elements were entered, the user cannot modify or clear the 7th element.

2. Provide a menu style interface to test all the operations of your porgram.

Example 3. " Welcome to the world of Arrays. Please enter from the following options: *To input values in the array enter i or I To see statistics, enter s or S To count an element enter c or C etc.... Enter choice : "

Please help me with this problem!!!!

Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Hello ryan157,

Looking over your instruction they are very good. Some of the best I have seen in a long time. In the "important" section, in red, points 4 and 5 are the most important. Keep those in mind ALWAYS.

The easiest part to start with is the menu. I like to put a menu in its own function printing the menu, getting user input and verify the input before returning a valid input. It looks like you are being directed into using letters for the menu choices. I would use capital letters only. Then after the "std::cin >> choice;", I tend to use the variable name "choice" for this, it is helpful to use the function "std::toupper()" as in choice = std::toupper(choice);. This will change a lower case letter to upper case and if the letter is already upper case nothing happens. This way you are only dealing with one case for your inputs, if and while conditions now only have to deal with only one case. The "std::tolower" and "std::toupper", along with some other very useful functions, is found in the <cctype> header file.

I like to start with the menu because the menu choices will give you an idea of what other parts of the program you will need to work with. Also when you have a valid menu choice returned this will give you an idea of how to deal with the value, i.e., if, if/else if, statements or a switch.

Work on that and post some code when you have a problem or question and we can go from there.

Hope that helps,

Andy
Topic archived. No new replies allowed.