Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,056 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




making a MENU of computer actions

 
Reply to this topicStart new topic

making a MENU of computer actions, Menu needs to make option number (5) shutdown

rollin4deshi
3 Aug, 2008 - 10:24 PM
Post #1

New D.I.C Head
*

Joined: 31 Jul, 2008
Posts: 4

i wrote up a code from one of my c++ books and its all good and well but i would like it instead of jus doing a simple cout " o hai!" i want it to do sumthin though this code was wrote mostly in a forever loop and switch case typa style ..my main question is it possible to make a switch case style actually do sumthin other then jus take an input ..can i make a case(5):
DoShutDown;
break;
heres the original code, and i have the shutdown code jus not sure if it would work in the original code and or in the switch case style. thanks, kc
CODE

#include <iostream>
int menu();
void DoTaskOne();
void DoTaskMany(int);

using namespace std;
int main()
{
    bool exit= false;
    for(;;)
    {
           int choice = menu();
           switch(choice)
           {
                         case(1):
                         DoTaskOne();
                         break;
                         case(2):
                            DoTaskMany(2);
                             break;
                             case(3):
                                 DoTaskMany(3);
                                 break;
                                 case(4):
                                         continue;
                                         break;
                                         case(5):
                                         exit = true;
                                         break;
                                         default:
                                                 cout<<"Please select again!"<<endl;
                                                 break;
                                                 }
if (exit==true)
break;
}
return 0;
}
int menu ()
{
    int choice;
    cout<<"**** Menu ****"<<endl<<endl;
    cout<<"(1) Choice one."<<endl;
    cout<<"(2) Choice two."<<endl;
    cout<<"(3) Choice three."<<endl;
    cout<<"(4) Redisplay Menu."<<endl;
    cout<<"(5) Quit."<<endl<<endl;
    cout<<":";
    cin>>choice;
    return choice;
}
void DoTaskOne ()
{
     cout<<"Task One!"<<endl;
     }
     void DoTaskMany(int which)
     {
          if (which==2)
          cout<<"Task Two!"<<endl;
          else
          cout<<"Task Three!"<<endl;
          }


This post has been edited by NickDMax: 3 Aug, 2008 - 10:26 PM
User is offlineProfile CardPM
+Quote Post

jwwicks
RE: Making A MENU Of Computer Actions
4 Aug, 2008 - 01:08 AM
Post #2

D.I.C Head
Group Icon

Joined: 31 Jul, 2008
Posts: 59



Thanked: 6 times
Dream Kudos: 200
My Contributions
Hello rollin4deshi,

QUOTE(rollin4deshi @ 3 Aug, 2008 - 11:24 PM) *

i wrote up a code from one of my c++ books and its all good and well but i would like it instead of jus doing a simple cout " o hai!" i want it to do sumthin though this code was wrote mostly in a forever loop and switch case typa style ..my main question is it possible to make a switch case style actually do sumthin other then jus take an input ..can i make a

cpp

case 5:
DoShutDown;
break;



Sure, that's fine. I normally use a a different loop style....

cpp

const int QUIT = 0;

int main( int argc, char* argv[] )
{
int ret_val = 0;

do{

do{
choice = get_choice();
}while(!is_valid_choice(choice));

switch(choice){
case 1:
break;
//etc...
}

}while(choice!=QUIT)

return ret_val;
}


JW
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 05:57PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month