Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
It seems like I need to do it with do while loops, but I don't really understand how to make it work yet. I've figured out how to create the functions for the menu but not how to create the menu or how to have the initial scan, scan into both functions.

A sample run is supposed to look like

Enter a text message: Sing a song.

Available choices:
1. Display number of occurrences of each letter
2. Print number of words in message
3. Quit

Enter the number of your choice:
Posted
Comments
Sergey Alexandrovich Kryukov 11-Mar-14 2:31am    
The question makes no sense, because the answer would depend on platform, UI framework/library you use, and so on. Please specify all what apply.
—SA
Nelek 11-Mar-14 5:29am    
For future questions, please read: What have you tried?[^]

1 solution

A simple menu would be just a printed list, followed by an input command, and then some choices. Something like:
C++
int choice = -1;
do
{
    printf("Enter choice from the following:\n");
    printf("0. Quit\n");
    printf("1. Enter words:\n");
    printf("2. Count the words:\n");
    printf("3. Reverse the sentence:\n");
    printf("4 ...:\n"); // etc ...
    scanf("%d", &choice);
    if (choice == 0)
        break;
    switch (choice)
    {
    case 1:
        // do some work
        break;
    // etc
    default:
        printf("Bad choice: %d, try again\n", choice);
        break;
    }
} while (1);
 
Share this answer
 
Comments
CPallini 11-Mar-14 5:17am    
5.It is harmless in such a case, however, the OP has to always check the return value of scanf.
Richard MacCutchan 11-Mar-14 5:49am    
I did think of that, but then I thought, "What the hell, let's live dangerously". :)
CPallini 11-Mar-14 5:56am    
Well, we all know Richard The Lionheart, nevertheless we cannot leave the OP in dangerous waters. :-D
nv3 11-Mar-14 6:09am    
+5. That is what OP probably needed, a simple example of a non-graphical menu.
Richard MacCutchan 11-Mar-14 6:19am    
It's interesting how many such 'basic questions' seem to be so difficult for some people, even to visualise how to present a simple list menu. When I started, that was the only way to operate so it seems fairly logical. But if your entire computer experience is GUI and touch (which is the norm these days), this probably seems quite alien. I read recently that children (and even some teens) presented with an old style dial telephone, cannot figure out how to make a call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900