473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How can we write a menu using switch statement?

I'm using a dev c++ bloodshed compiler.
Aug 17 '12 #1
1 2658
divideby0
131 128KB
Expand|Select|Wrap|Line Numbers
  1. loop { 
  2.    menu prompt
  3.    read choice
  4.    validate choice
  5.  
  6.    switch choice
  7.       choice branch(es)
  8. }
if you mean a user interface sort of thing.

if you literally mean print a menu using a switch, then use a loop with the number of options as the upper bound. switch the iteration printing out the choice under each case.

Expand|Select|Wrap|Line Numbers
  1. static char *choices[] = { "option 1", "..." };
  2.  
  3. for(i=1; i <= max_choices; ++i) {
  4.    switch(i) {
  5.       case 1 : print choices[i - 1];
  6.                break;
  7.       ""
  8.    }
  9. }
Aug 17 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: ChrisB | last post by:
I have two pieces of code show below. The first contains a switch statement. The second contains a text shown on the console application screen. The simple menu shows up fine, I enter a number...
35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
2
by: Ubha | last post by:
Dear all, I have one question. Enter a persons weight in kilograms and height in metres. Calculate the persons Quetelet Index (kolos/(meters *meters)). Print out the Quetelet Index and an...
67
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is...
4
by: jla1357 | last post by:
I have to create a switch statement that calls a statement when one of the choices is selected. i.e. cout << "Please select a choice from the menu below: " << endl; cout << "F)ind a word by...
5
by: CSharper | last post by:
I have a hashtable which has key and value. If the key is set to 'a' then I need to create a class1 and if it has key 'b' then I need to create class2 etc. (There is no name relation between the...
9
by: 16800960 | last post by:
Here is the code for my program // Book Price (16800960) #include <iostream> #include <string> #include <iomanip> const int MAXSIZE 300;
1
by: Frakes | last post by:
I'm using a hyperlink to pass a value from a home page to a search page. I'm using to values to identify and display only certain input/select boxs that relate to whatever unique search the user...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.