0

Below was my original problem now i have done the following. Which is really just the structure for what needs to happen. Where i have written after my // basically i dont know how to do that part any help would be great.

Cheers

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    const int array_size = 5;
    string adjectives_1[array_size] = ( "Green", "Blue", "Fast", "Dark", "Evil");
    string adjectives_2[array_size] = ( "Yellow", "Red", "Slow", "Light", "Holy");
    string nouns[array_size] = ("Cat", "Dog", "TV", "Car", "Heater");
    
    int cells_used = 4;
    
    
    // Main menu
    
    char main_menu_selection;
    
    cout << "******************************************************************" << endl;
    cout << "Press A to add a word" << endl
    << "Press D to delete a word" << endl
    << "Press L to display a list" << endl
    << "Press S to display a randomly generated sentence" << endl;
    cout << "******************************************************************"<< endl;
    
    
    cin >> main_menu_selection;
    
    switch (main_menu_selection)
    {
           case 'A':
                cout << "******************************************************************"<< endl;
                cout << " To add a word you have to..." << endl
                << " 1: Type in add..." << endl
                << " 2: Type in the list number you would like to add it to..." << endl
                << " 3: Then type in the word you would like to add" << endl
                << "    * e.g. add 2 nice" << endl
                << "    * This will add the word nice to list 2" << endl;
                cout << "******************************************************************"<< endl;
                
                // Need to add the actual code to let the user input word...
                
                break;
           case 'D':
                cout << "******************************************************************"<< endl;
                cout << " To delete a word you have to..." << endl
                << " 1: Type in delete..." << endl
                << " 2: Type in the list number you would like delete the word from..." << endl
                << " 3: Type in the word you would like to delete" << endl
                << "    * e.g. delete 3 cat" << endl
                << "    * This will delete the word cat from list 3" << endl;
                cout << "******************************************************************"<< endl;
                
                // Need to add the actual code to let the user delete word...
                
                break;                                    
           case 'L':
                cout << "******************************************************************"<< endl;
                cout << " To list the words from the first list of adjectives press A" << endl
                << " To list the words from the second list of adjectives press B" << endl
                << " To list the words from the list of nouns press C" << endl
                << " To list all the words from all the lists press D" << endl;
                cout << "******************************************************************"<< endl;
                
                // Need to add the code to let the user see the above options...
                
                
           case 'S':
                cout << "******************************************************************"<< endl;
                cout<< "Enter the number of sentences you would like generated" << endl
                <<     "Your randomly generated sentence are..." << endl;
                cout << "******************************************************************"<< endl;
                
                // add the code above for this to work
                
                break;
                
           default:
                cout << " That is not a possible selection..." << endl;
                
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

Ok i have to do the following

*Just a console program

* Have a program with three lists, List 1 = Adjectives, List 2 = Adjectives, List 3 = Nouns.

* The user will say if they want to input a word into the list, delete a word from the list, or display the list.

* Or exit the program

* Once the user has either added a word deleted a word or just wants the program to display the words then the following has to happen...

* The three lists are displayed. Then the program has to select a word at random from each list and display the sentence.

I wanted a main menu which had the following...

* To add a word press 1
* To delete a word press 2
* To display list press 3
* To display a randomly generated sentence press 4

Once one of these has been selected it will go to the sub menu for the thing they selected.

eg if add is selected it will go to the following

To add a word you have to
type in add
type in the list number you would like to add it to
then type in the word you would like to add
e.g. add 2 nice.

Then it will go back to the original menu.

I know i need to use three arrays to do this, and I have made a program which will allow the user to input words into an array and then that will mix those words up and print them on the screen but I'm not sure how to go about doing this with all the menu's and sub menu's etc.

Any help would be much appreciated

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by ravenous
0

This seems like a good start to me. The bit for actually doing stuff is mostly about checking that the inputs are sensible. If you want to get input like you suggest, i.e. add 2 grey then you should use

getline(cin,my_string);

and attempt to split the string on the spaces and get the bits you want. However, in a case where you know that the input will ALWAYS be in the same form, you could cheat and do something like

int position;
char command[11];
string newWord;

cout << "Enter you parameters:" << endl;
cin >> command >> position >> newWord;

and then do all the processing and checking etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.