473,387 Members | 1,512 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.

Unreachable Code in C++ ?, When use my file management code, other wise all right

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<fstream.h>
  5. class student
  6.     {
  7.     private:
  8.         int adm,scl;
  9.         char sname[15],ssec;
  10.     public:
  11.         void add(void)
  12.             {
  13.             clrscr();
  14.             cout << "\n\n\nEnter Student Information :";
  15.             cout << "\n\n Student No      :";
  16.             cin >> adm;
  17.             cout << "\n\n Student Name    :";
  18.             cin >> sname;
  19.             cout << "\n\n Student Class   :";
  20.             cin >> scl;
  21.             cout << "\n\n Student Section :";
  22.             cin >> ssec;
  23.             }
  24.         void mod(int no,int tstd,student *as)
  25.             {
  26.             }
  27.         void del(int no,int tstd,student *as)
  28.             {
  29.             }
  30.  
  31.         void vie(void)
  32.             {
  33.             }
  34.  
  35.     };
  36. class book
  37.     {
  38.     private:
  39.         int bno,bprice;
  40.         char bname[15],bauthor[15];
  41.     public:
  42.         void add(void)
  43.             {
  44.  
  45.             }
  46.         void mod(void)
  47.             {
  48.  
  49.             }
  50.         void del(void)
  51.             {
  52.  
  53.             }
  54.         void vie(void)
  55.             {
  56.  
  57.             }
  58.  
  59.     };
  60. void main()
  61. {
  62. int i,ch,sub,sinput;
  63. mainmenu:
  64. clrscr();
  65. cout << "                            Main Menu \n";
  66. cout << "                            ~~~~~~~~~\n\n\n\n";
  67. cout << "                          1.....Master\n\n";
  68. cout << "                          2.....Borrow Book\n\n";
  69. cout << "                          3.....Received Book\n\n";
  70. cout << "                          0.....Exit\n\n";
  71. cout << "                         ---------------------\n\n";
  72. cout << "                          Select :  ";
  73. cin >> ch;
  74. if (ch==1)
  75.     {
  76.     goto submenu;
  77.     }
  78. else if(ch==2)
  79.     {
  80.     goto borrowmenu;
  81.     }
  82. else if(ch==3)
  83.     {
  84.     goto receivemenu;
  85.  
  86.     }
  87. else if(ch==0)
  88.     {
  89.     cout << "\n\n\n                  Thanks for visit my project....";
  90.     getch();
  91.     return;
  92.     }
  93. else
  94.     {
  95.     cout << "\n\n\n                  Invalid choice try again : ";
  96.     getch();
  97.     goto mainmenu;
  98.     }
  99. submenu:
  100. clrscr();
  101. cout << "                            Submenu\n";
  102. cout << "                            ~~~~~~~\n\n\n\n";
  103. cout << "                          1...Student\n\n";
  104. cout << "                          2...Books\n\n";
  105. cout << "                          0...Back\n\n";
  106. cout << "                         --------------\n\n";
  107. cout << "                          Select : ";
  108. cin >> sub;
  109. if(sub==1)
  110.     {
  111.     goto studentmenu;
  112.     }
  113. else if(sub==2)
  114.     {
  115.     goto bookmenu;
  116.     }
  117. else if(sub==0)
  118.     {
  119.     goto mainmenu;
  120.     }
  121. else
  122.     {
  123.     cout << "\n\n                   Invalid choice :";
  124.     goto submenu;
  125.     }
  126.  
  127. studentmenu:
  128. clrscr();
  129. cout << "\n\n\n                          This is student menu :";
  130. cout << "\n\n                           1... Add student ";
  131. cout << "\n\n                           2....Modify Student";
  132. cout << "\n\n                           3....Delete Student";
  133. cout << "\n\n                           4....View Student";
  134. cout << "\n\n                           0....Back";
  135. cout << "\n\n                          ------------------------- ";
  136. cout << "\n\n                           select : ";
  137. cin >> sinput;
  138.  
  139. if(sinput==1)
  140.     {
  141.     goto addstudent;
  142.     }
  143. else if(sinput==2)
  144.     {
  145.     goto modifystudent;
  146.     }
  147. else if(sinput==3)
  148.     {
  149.     goto deletestudent;
  150.     }
  151. else if(sinput==4)
  152.     {
  153.     goto viewstudent;
  154.     }
  155. else if(sinput==0)
  156.     {
  157.     goto submenu;
  158.     }
  159. else
  160.     {
  161.     cout << "\n\n                   Invalid choice :";
  162.     goto studentmenu;
  163.     }
  164. goto submenu;
  165.  
  166. bookmenu:
  167. clrscr();
  168. cout << "\n\n\n                          This is book menu :";
  169. getch();
  170. goto submenu;
  171.  
  172. borrowmenu:
  173. clrscr();
  174. cout << "\n\n\n                          This is borrow menu :";
  175. getch();
  176. goto mainmenu;
  177.  
  178. receivemenu:
  179. clrscr();
  180. cout << "\n\n\n                          This is receive menu :";
  181. getch();
  182. goto mainmenu;
  183.  
  184.  
  185.  
  186.  
  187. addstudent:
  188. clrscr();
  189. cout << "\n\n\n                          This is Add New Student menu :";
  190. student s;
  191. s.add();
  192. ofstream obj1("std.txt");
  193. obj1.write((char *)&s,sizeof(s));
  194. obj1.close();
  195. getch();
  196. goto studentmenu;
  197.  
  198. modifystudent:
  199. clrscr();
  200. cout << "\n\n\n                          This is Modify Old Student menu :";
  201. getch();
  202. goto studentmenu;
  203.  
  204. deletestudent:
  205. clrscr();
  206. cout << "\n\n\n                          This is Delete Old Student menu :";
  207. getch();
  208. goto studentmenu;
  209.  
  210. viewstudent:
  211. clrscr();
  212. cout << "\n\n\n                          This is View Student menu :";
  213. cout << "\n--------------------------------------------------------------------------";
  214. getch();
  215. goto studentmenu;
  216. }
Attached Files
File Type: txt NL.txt (4.2 KB, 381 views)
Dec 5 '10 #1
2 2515
Savage
1,764 Expert 1GB
I dont know what you mean with "my file managment code, otherwise its fine", but I do see a lot of goto's which is a bad thing, since they ruin program flow and make it less readable.Generally, you can write every structured programme without using goto's and in most cases you should go that way.So use goto's only when they are necessary (which is a rare thing) and use other language constructs to structure your code in a more readable form.

Also, this might be a good read :)

Regards
Dec 5 '10 #2
Oralloy
988 Expert 512MB
Tarun,

C and C++ both have a switch statement. Use of the statement can really make your life easier.

Savage pointed out the "goto" issue your code has; but that's not what's causing you grief at the moment.

To find the "Unreachable Code", read your complier's error message and go to the line it calls out. The problem is likely the line immediately preceeding.

Luck!
Orally
Dec 6 '10 #3

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

Similar topics

2
by: kaiwing18 | last post by:
Hi , I use apache server , php and mysql to implement a multi-language web admin system, in order to display the required language, the file needed to save with unicode instead of ANSI. But...
4
by: TempEcho | last post by:
Is there any place where I can find some library / commands to use for file management (e.g. renaming files , copying , deleting?). Thanks in advance! T.E.
0
by: Carlos | last post by:
Does anyone know a good "file management" ASP.NET program out there, so I can get it and learn how to do it ? Thanks
2
by: Matthias H. | last post by:
Hi guys, Our team has a very strange problem. I hope anybody can help. We have a class called webpage and all our aspx-pages bases on it. Then we have a SYS.IO.File Class which have a...
19
by: Alan Silver | last post by:
Hello, I have been developing ASP.NET with a text editor so far (better way to learn initially), and have now been trying Visual Web Developer. I want to create a project for an existing site...
1
by: s | last post by:
I need to coordinate file management between three computers. Users need to enter all file names and would like to store file names,date changed,person changed etc. into a database. User...
5
by: yazwas | last post by:
Hi, I'm looking for a file management library in C++, i.e library that has createfile, readfile, movefile, ...etc I need it for linux espically, it no general one is available does anyone have...
1
by: systemonkey | last post by:
I have a lot of huge files on a server and I can't risk getting deleted by anyone. What I have been doing is I create a ftp account for users and create a hardlinks to the original file in case...
10
by: mzmishra | last post by:
Hi, I have one page developed in C# ASP.NET 2.0. I am trying to open a new window from my code behind file. My code is like below string pageName = "EntityDescription.aspx?Ecode=" + "'" +...
0
by: lgwapnitsky | last post by:
I am writing an Outlook add-in that needs to fire when a PST is added/removed. I have successfully fired the event using the AddStore and RemoveStore functions, as well as when I use the "Open ->...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.