473,396 Members | 1,816 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,396 software developers and data experts.

return to "menu"

18
hi

as shown in the source, i wanted to return to 'choice' in the 'switch' statement so that user can input their choices again after they chose the option.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <conio.h>
  5. #define MAX_STUDENT 100
  6. using namespace std;
  7.  
  8. struct stud
  9. {
  10.     char id[8];
  11.     char name[20];
  12.     char address[30];
  13.     int  telephone;
  14. };
  15.  
  16. int main()
  17.  
  18. {
  19.  
  20.     //diaplay welcome message
  21.     cout << "Welcome to student information panel"<< endl;  
  22.     //ask to login
  23.     cout << "Please enter password to logon" << endl; 
  24.  
  25. int security = 0;
  26.  
  27.  
  28.     do {
  29.     string username;
  30.     cout << "\nUsername: ";
  31.     cin >> username;
  32.  
  33.     string 
  34.     password;
  35.     cout << "Password: ";
  36.     cin >> password;
  37.  
  38.     //if user enter correct username and password
  39.     if (username == "1" && password == "1") 
  40.     {            
  41.                  //clear the screen   
  42.                  system("cls");
  43.  
  44.                              {                                                  // CHOICE STATEMENT OPEN        
  45.                                       char choice;
  46.                                       cout << "Welcome Admin\n\n1. Add New Student\n2. Delete Student\n3. Update Student\n4. Display All\n5. Save As Text\n6. Save As Binary\n7. Quit\n\n";
  47.                                       cin >> choice;
  48.                                                     while ( choice <='0' || choice > '7')
  49.                                                     {
  50.                                                           system("cls");
  51.                                                           cout << "Please Enter A Vaild Option\n";
  52.                                                           cout << "Welcome Admin\n\n1. Add New Student\n2. Delete Student\n3. Update Student\n4. Display All\n5. Save As Text\n6. Save As Binary\n7. Quit\n\n";
  53.                                                           cin >> choice;
  54.                                                     }
  55.  
  56.                                       switch(choice)
  57.  
  58.                                       {                                         // SWITCH STATEMENT OPEN
  59.                                                     case'1':system("cls");
  60.                                                             cout<<"You Have Entered Add New Student Page.\n";                                                                       
  61.                                                             cout<<"ADD NEW STUDENT.\n\n\n\n";
  62.  
  63.  
  64.                                                     break;
  65.  
  66.                                                     case'2':system("cls");
  67.                                                             cout<<"Your Have Entered Delete Student Page\n";               
  68.                                                             cout<<"DELETE STUDENT"; 
  69.  
  70.  
  71.                                                     break;
  72.  
  73.                                                     case'3':system("cls");
  74.                                                             cout<<"You Have Entered Update student Page.\n";                                         
  75.                                                             cout<<"UPDATE";
  76.  
  77.                                                     break;
  78.  
  79.                                                     case'4':system("cls");
  80.                                                             cout<<"Your Have Entered Display All Student Page\n";                                                                             
  81.                                                             cout<<"DISPLAY\n\n\n\n"; 
  82.  
  83.  
  84.  
  85.  
  86.  
  87.                                                     break;                        
  88.  
  89.                                                     case'5':system("cls");
  90.                                                             cout<<"You Have Entered Save As Text Page.\n";                                                                       
  91.                                                             cout<<"SAVE TEXT";
  92.  
  93.                                                     break;
  94.  
  95.                                                     case'6':system("cls");
  96.                                                             cout<<"Your Have Entered Save As Binary Page\n";                                                                             
  97.                                                             cout<<"SAVE BINARY\n\n\n\n";
  98.  
  99.                                                     break;
  100.  
  101.                                                     case'7':
  102.                                                             system("cls");
  103.                                                             cout << "System Shutting Down\n";
  104.                                                             system("pause");           
  105.                                                             return 0;                                                                           
  106.  
  107.                                                     break;                                                                             
  108.  
  109.                                       }                                         // SWITCH STATEMENT CLOSE
  110.  
  111.                              }                                                  // CHOICE STATEMENT CLOSE
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.     security = 5;
  121.     }
  122.  
  123.     if (!security) //if user enter incorrect password or username
  124.  
  125.        cout << "\nYour login has failed. Please check your username and password and try again\n\n";
  126.     } while (!security);
  127.  
  128.  
  129. getch(); 
  130. return 0;
  131. }
  132.  
  133.  
so the question is, how can i loop back to the 'choice' for every case? thank you
Jul 21 '08 #1
1 8589
weaknessforcats
9,208 Expert Mod 8TB
Use a loop maybe?
Expand|Select|Wrap|Line Numbers
  1. while (1)
  2. {
  3.     cin >> choice;
  4.     switch (choice)
  5.     {
  6.         case 1:
  7.             Add();
  8.             break;
  9.         case 2:
  10.             exit();         //this is the quit choice.
  11.  
  12. }
  13.  
Jul 22 '08 #2

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

Similar topics

32
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at...
7
by: William Payne | last post by:
Hello, have you seen a recent files menu in a GUI application? In many GUI applications there's a menu the displays the most recent files that has been opened by the program. Say such a menu has...
1
by: Mary Ann | last post by:
I would like to write code in the On Open property of a form that hides the main menu bar toolbar. I have already customized the menu bar to all for showing/hiding but have no clue how to write...
2
by: Jerry Boone | last post by:
Funny thing happened today... I thought I was going to be smart and customize my menu's by dragging the Refresh option from the Records menu onto the toolbar in Access 2000. When doing so, I...
2
by: Robin S. | last post by:
I don't have the "references" selection in my "tools" menu. Obviously this is kind of important. I have "Always show full menus" checked. Program has been updated to SP3. Any ideas as to why...
8
by: Ken Yu | last post by:
Hi, How can i disable "RightClick Menu" in Internet Explorer, when access the frontpage ? tks a lot ! Ken
4
by: Firoz72000 | last post by:
Hi All, I am using WindowsXP operating system. I was able to hide the files and to see them : I was going to the "Tool" menu then "Folder Option" and then "View" tab and "show the hidden files and...
1
by: rmgalante | last post by:
I was wondering if anyone knows whether MS has a fix for the Menu Control. If the page is loading while you mouse over a menu control with child menus that pop out, you can generate the following...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.