473,804 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return to "menu"

18 New Member
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 8658
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
33076
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 the first time the page is loaded). I tryed this code:
7
2034
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 four entries and the most recent file is displayed on top and the oldest at the bottom. New entries are added at the top, pushing the oldest of the list. I wrote a class which I've named CircularContainer (please help me think of a better name!)...
1
15970
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 the code in the form. Is it even possible to do this? If so, how? Thanks!
2
2339
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 missed and dropped it onto the dark mdi window and it was as if it fell in a black hole... and worse... it's not in the menu anymore either. Is this a reinstall... or has anyone else made this bloop and fixed it? I tried to recreate it, but doesn't...
2
2438
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 this would be completely missing? Perhaps a security setting? Is there another way to turn on DAO 3.6? Thanks for any thoughts. Regards,
8
2480
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
4933
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 folders" check box ... But from some days I am not able to get that "Folder Option" in the menu from the "Tool" menu. So I am not able to understand that why this is not showing. I sthere any .dll file is corrupted or what????? So please help...
1
2019
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 error in IE. Internet Explorer cannot open the Internet site... http://www.... Operation aborted
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9175
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.