473,503 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

so i'm getting this error: Error 14 error C2360: initialization of 'levelTwo' is skip

2 New Member
i"m new at this.. please help me! i keep getting this error Error 5 error C2360: initialization of 'levelOne' is skipped by 'case' label.
I get a "transfer of control bypasses initialization of:" error when i try to build the following switch:



Expand|Select|Wrap|Line Numbers
  1. int SelectCourses()
  2. {
  3.     int choice=0;
  4.     string course;
  5.  
  6.     cout<<"Enter Level"<<endl;
  7.     cin>> choice;
  8.  
  9.     ofstream MyCourses;
  10.     MyCourses.open("Courses.txt",ios::out);
  11.  
  12.     if (!MyCourses)
  13.     {
  14.         ofstream ("Courses.txt",ios::out);
  15.     }
  16.     else
  17.     {
  18.         cerr<<"failed to find file"<<endl;
  19.         (EXIT_FAILURE);
  20.    }
  21.     switch(choice)
  22.     {
  23.     case 1: ifstream levelOne;
  24.         levelOne.open("Level1.txt");
  25.         cout<<"Select any  4 or 4 modules from the list provided"<<endl;
  26.         cout<<"Option 1:"<<endl;"/t";
  27.                         cout<<"Option 2:"<<endl;"/t";
  28.                         cout<<"Option 3:"<<endl;"/t";
  29.                         cout<<"Option 4:"<<endl;"/t";
  30.                         cout<<"Option 5:"<<endl;"/t";
  31.                         cin>>course;
  32.                         break;
  33.     case 2: ifstream levelTwo;
  34.         levelTwo.open("level2.txt");
  35.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  36.                         cout<<"Option 1:"<<endl;"/t";
  37.                         cout<<"Option 2:"<<endl;"/t";
  38.                         cout<<"Option 3:"<<endl;"/t";
  39.                         cout<<"Option 4:"<<endl;"/t";
  40.                         cout<<"Option 5:"<<endl;"/t";
  41.                         cin>>course;
  42.                         break;
  43.     case 3: ifstream levelThree;
  44.         levelThree.open("level3.txt");
  45.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  46.                         cout<<"Option 1:"<<endl;"/t";
  47.                         cout<<"Option 2:"<<endl;"/t";
  48.                         cout<<"Option 3:"<<endl;"/t";
  49.                         cout<<"Option 4:"<<endl;"/t";
  50.                         cout<<"Option 5:"<<endl;"/t";
  51.                         cin>>course;
  52.                         break;
  53.  
  54.     case 4: ifstream levelFour;
  55.         levelFour.open("level4.txt");
  56.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  57.                         cout<<"Option 1:"<<endl;"/t";
  58.                         cout<<"Option 2:"<<endl;"/t";
  59.                         cout<<"Option 3:"<<endl;"/t";
  60.                         cout<<"Option 4:"<<endl;"/t";
  61.                         cout<<"Option 5:"<<endl;"/t";
  62.                         cin>>course;
  63.                         break;
  64.  
  65.     case 5: ifstream levelFive;
  66.         levelFive.open("level5.txt");
  67.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  68.                         cout<<"Option 1:"<<endl;"/t";
  69.                         cout<<"Option 2:"<<endl;"/t";
  70.                         cout<<"Option 3:"<<endl;"/t";
  71.                         cout<<"Option 4:"<<endl;"/t";
  72.                         cout<<"Option 5:"<<endl;"/t";
  73.                         cin>>course;
  74.                         break;
  75.  
  76.     default: cout << "Invalid option please try again" << endl;//when an incorrect option is entered
  77.                             break;
  78.  
  79.                             MyCourses.close();
  80.  
  81.     }
  82. }
Apr 6 '14 #1
2 1590
Temper
2 New Member
i solved it thou..thanks alot for not helping..
but for the sake of someone who is in a bind; such as my previous situation

solution is:

Expand|Select|Wrap|Line Numbers
  1.  
  2.             switch(choice)
  3.     {
  4.     case 1: {ifstream levelOne;
  5.         levelOne.open("Level1.txt");
  6.         cout<<"Select any  4 or 4 modules from the list provided"<<endl;
  7.         cout<<"Option 1:"<<endl;"/t";
  8.                         cout<<"Option 2:"<<endl;"/t";
  9.                         cout<<"Option 3:"<<endl;"/t";
  10.                         cout<<"Option 4:"<<endl;"/t";
  11.                         cout<<"Option 5:"<<endl;"/t";
  12.                         cin>>course;
  13.                         break;}
  14.     case 2:{ ifstream levelTwo;
  15.         levelTwo.open("level2.txt");
  16.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  17.                         cout<<"Option 1:"<<endl;"/t";
  18.                         cout<<"Option 2:"<<endl;"/t";
  19.                         cout<<"Option 3:"<<endl;"/t";
  20.                         cout<<"Option 4:"<<endl;"/t";
  21.                         cout<<"Option 5:"<<endl;"/t";
  22.                         cin>>course;
  23.                         break;}
  24.     case 3: {ifstream levelThree;
  25.         levelThree.open("level3.txt");
  26.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  27.                         cout<<"Option 1:"<<endl;"/t";
  28.                         cout<<"Option 2:"<<endl;"/t";
  29.                         cout<<"Option 3:"<<endl;"/t";
  30.                         cout<<"Option 4:"<<endl;"/t";
  31.                         cout<<"Option 5:"<<endl;"/t";
  32.                         cin>>course;
  33.                         break;}
  34.  
  35.     case 4: {ifstream levelFour;
  36.         levelFour.open("level4.txt");
  37.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  38.                         cout<<"Option 1:"<<endl;"/t";
  39.                         cout<<"Option 2:"<<endl;"/t";
  40.                         cout<<"Option 3:"<<endl;"/t";
  41.                         cout<<"Option 4:"<<endl;"/t";
  42.                         cout<<"Option 5:"<<endl;"/t";
  43.                         cin>>course;
  44.                         break;}
  45.  
  46.     case 5: {ifstream levelFive;
  47.         levelFive.open("level5.txt");
  48.         cout<<"Select any  4 or 5 modules from the list provided:"<<endl;
  49.                         cout<<"Option 1:"<<endl;"/t";
  50.                         cout<<"Option 2:"<<endl;"/t";
  51.                         cout<<"Option 3:"<<endl;"/t";
  52.                         cout<<"Option 4:"<<endl;"/t";
  53.                         cout<<"Option 5:"<<endl;"/t";
  54.                         cin>>course;
  55.                         break;}
  56.  
  57.     default:{ cout << "Invalid option please try again" << endl;//when an incorrect option is entered
  58.         break;}
  59.  
  60.                             MyCourses.close();
  61.  
  62.     }
  63. }
Apr 7 '14 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Probably you don't need the braces. I suspect the case line must end with the colon. Just move the code after the colon to the next line.

The brace forces a change of scope and would act like a newline key.

It's like the #include. You can't put anything on those lines either.
Apr 7 '14 #3

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

Similar topics

3
1985
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
9986
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
1
1941
by: bagya | last post by:
please help me out the following is the small code i have <html> <head> <script type="text/javascript"> function validate() { if (document.abc.region.value==0)
8
4663
by: ipy2006 | last post by:
In my HTML I have, <input type="button" class="cartonsumkey" value="Sum Cartons" onclick="sumup(this);" /> In an external file that is called in Head area, I have, function sumup( o ) { ...
5
9103
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
0
1072
by: satishwise | last post by:
HELLO EVERYONE PLEASE HELP ME ON THIS I followed the installation instructions from the oracle 9i built in documentation and started the installation with the Result of this output on my...
4
24927
by: clairelee0322 | last post by:
My program has an error C2360: initialization of 'i' is skipped by 'case' label. I don't know why. Please help me out! thks!! the error occurs in Division case 3. //Claire's Calculator...
21
3799
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
3200
by: bandy | last post by:
Hi there sorry If I posted this thread under wrong head. When I am trying to run my site I am getting error as Internal Server Error, but when I refresh page , i get result properly. I don't...
0
7093
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
7291
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
7357
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...
0
7468
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
5598
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,...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.