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:
I get a "transfer of control bypasses initialization of:" error when i try to build the following switch:
Code:
int SelectCourses()
{
int choice=0;
string course;
cout<<"Enter Level"<<endl;
cin>> choice;
ofstream MyCourses;
MyCourses.open("Courses.txt",ios::out);
if (!MyCourses)
{
ofstream ("Courses.txt",ios::out);
}
else
{
cerr<<"failed to find file"<<endl;
(EXIT_FAILURE);
}
switch(choice)
{
case 1: ifstream levelOne;
levelOne.open("Level1.txt");
cout<<"Select any 4 or 4 modules from the list provided"<<endl;
cout<<"Option 1:"<<endl;"/t";
cout<<"Option 2:"<<endl;"/t";
cout<<"Option 3:"<<endl;"/t";
cout<<"Option 4:"<<endl;"/t";
cout<<"Option 5:"<<endl;"/t";
cin>>course;
break;
case 2: ifstream levelTwo;
levelTwo.open("level2.txt");
cout<<"Select any 4 or 5 modules from the list provided:"<<endl;
cout<<"Option 1:"<<endl;"/t";
cout<<"Option 2:"<<endl;"/t";
cout<<"Option 3:"<<endl;"/t";
cout<<"Option 4:"<<endl;"/t";
cout<<"Option 5:"<<endl;"/t";
cin>>course;
break;
case 3: ifstream levelThree;
levelThree.open("level3.txt");
cout<<"Select any 4 or 5 modules from the list provided:"<<endl;
cout<<"Option 1:"<<endl;"/t";
cout<<"Option 2:"<<endl;"/t";
cout<<"Option 3:"<<endl;"/t";
cout<<"Option 4:"<<endl;"/t";
cout<<"Option 5:"<<endl;"/t";
cin>>course;
break;
case 4: ifstream levelFour;
levelFour.open("level4.txt");
cout<<"Select any 4 or 5 modules from the list provided:"<<endl;
cout<<"Option 1:"<<endl;"/t";
cout<<"Option 2:"<<endl;"/t";
cout<<"Option 3:"<<endl;"/t";
cout<<"Option 4:"<<endl;"/t";
cout<<"Option 5:"<<endl;"/t";
cin>>course;
break;
case 5: ifstream levelFive;
levelFive.open("level5.txt");
cout<<"Select any 4 or 5 modules from the list provided:"<<endl;
cout<<"Option 1:"<<endl;"/t";
cout<<"Option 2:"<<endl;"/t";
cout<<"Option 3:"<<endl;"/t";
cout<<"Option 4:"<<endl;"/t";
cout<<"Option 5:"<<endl;"/t";
cin>>course;
break;
default: cout << "Invalid option please try again" << endl;//when an incorrect option is entered
break;
MyCourses.close();
}
}
Comment