Code:
if(testFile.good())
{
testFile.close();
int samefile;
cout<<"\nThere is a file at the current save location with the same name...";
cout<<"\n <1>Overwrite";
cout<<"\n <2>Rename Current File";
cout<<"\n <3>Quit";
cout<<"\n ->: ";
cin>>samefile;
switch(samefile)
{
case 1:
File.open(filename.c_str(), ios::out|ios::trunc);
File.close();
break;
case 2:
filename.clear();
cout<<"\nNew File Name: ";
cin>>filename;
filename.append(".txt");
break;
case 3:
Quit();
break;
default:
cout<<"\nNot a valid entry!";
cout<<"\n ->: ";
}
}
File.open(filename.c_str(), ios::out);
if(File.bad())
{
cout<<"File could not be created!";
Quit();
}
else
{
cout<<"\t\t\t\'"<<filename<<"\' was created!!"<<endl;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
}
ok my problem is this...
if the user enter 3 as a choice from the menu... it is suppose to quit...
all my quit function does is return 0;
but... instead... it goes on and creates the file anyway... even if i said return 0;...
is there another way to quit out of the whole function all together?
my objective is to quit if the user wants to quit... but if not create file...
should i do something like this?
Code:
switch(samefile)
{
case 1:
File.open(filename.c_str(), ios::out|ios::trunc);
File.close();
break;
case 2:
filename.clear();
cout<<"\nNew File Name: ";
cin>>filename;
filename.append(".txt");
break;
case 3:
done=true;
break;
default:
cout<<"\nNot a valid entry!";
cout<<"\n ->: ";
}
}
if(done==true)
{
Quit();
}
File.open(filename.c_str(), ios::out);
if(File.bad())
{
cout<<"File could not be created!";
Quit();
}
else
{
cout<<"\t\t\t\'"<<filename<<"\' was created!!"<<endl;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
}