Del() function not working ,unable to delete files from program

// ****************************************
// HEADER FILES USED
//*****************************************

#include
#include <conio.h>
#include
#include <stdlib.h>
#include // read from string and write to string using formatting facilities
#include <stdio.h>
#include
#include <stdio.h>
#include
#include <shlobj.h> // to use SHGetFolderPathA
#include <windows.h>
#include <direct.h>
#pragma comment(lib, “shell32.lib”)
using namespace std;
void newmemo();
void openmemo();
void header();
void Del();
//#############################################
// MAIN FUNCTION
//#############################################

void main()
{ system(“cls”);
cout << "***************************************************

  • CASH MEMO version 1.0. Built on Microsoft C++. *
  •     *
    

“;
cout<<”
Coded by :Siddharth Kumar “;
cout<<”
Class :XII ‘A’";
cout<<"
School :Oxford public School ";
getch();
system(“cls”);
header();
}

//**********************************************
// HEADER FUNCTION FOR ENTERING CHOICE
//**********************************************

void header(){
int choice;
do{

	cout<<"
1.  Create New Invoice ";
	cout<<"
2.  Open Existing Invoice ";
	cout<<"
3.  Delete File";
	cout<<"
4.  Exit ";

	cout<<"

 Enter your choice (1-4) ";
	cin>>choice;

	switch(choice)
	{    
	case 1:newmemo();

	case 2:openmemo();


	case 3:Del();

	case 4:cout<<"

Bye - Bye ";
exit(EXIT_SUCCESS); break;

	default :cout<<"

Wrong Choice";
cout<<"
Press any key to re-enter ";
getch();

	}
}while(choice!=3);

}

//***********************************
// NEWMEMO FUNCTION
//***********************************

void newmemo(){
cout << " Enter the total number of Items (MAX. 1000 accepted) : ";
int totalitems;
cin >> totalitems;
cout << "
";
const int item = 1000;
int x;
double total;
double cost[item];
double rate[item];
double quantity[item];
total=0;
string name[item];
int spreq; //space required in upname
int strupname; //string length of upname
int maxlenall=20; //max name length
for(x=1;x<=totalitems;x++){
cout << " Enter Product number " << x << " Name (MAX 25 char): ";
cin >> name[x];
cout << " Enter Product number " << x << " Rate (cost per unit in INR) : ";
cin >> rate[x];
cout << " Enter Product number " << x << " Quantity (Unit) : ";
cin >> quantity[x];
cost[x]=rate[x] * quantity[x];
cout << "
";
total += cost[x];
}
char path1[ MAX_PATH ];// MAX_PATH IS PRE DDEFINED IN WinDef.h ,used as string size definer

if (SHGetFolderPathA( NULL, CSIDL_APPDATA, NULL, 0, path1 ) != S_OK)  // creating path to store data files for variable path1
{
cout << "";
}
else
{
cout << " ";
}
stringstream pathss1; // streams variable pathss1 from memory to file
string s1;   

pathss1 << path1;  //streaming variable path1 with the help of pathss1
pathss1 >> s1;  // streaming path to store in s1

string billpath1=s1 + "\\CashMemoBills"; // path created for storage of files

mkdir( billpath1.c_str() ); // c_str() return pointer to null-terminated nonmutable array

stringstream ss1;

ss1 << path1 << "\\CashMemobills\\donot_delete.iid";

string iidname = ss1.str(); // return string copy of character array

FILE *file1;
int file1_exists;
const char * filename1=iidname.c_str();
file1=fopen(filename1,"r");
if (file1==NULL) file1_exists=0;
else {file1_exists=1; fclose(file1);}


if (file1_exists==1)
{
   file1=fopen(filename1,"r+b"); // open binary file for read/write
}
else
{
    file1=fopen(filename1,"w+b"); // create binary file for write/read
	ofstream out2(iidname); // opens file for writing with path stream of iidname 
    out2 << "0";
    out2.close();
}   
if (file1!=NULL)
{
   fclose(file1);
}
ifstream in1(iidname);
int num11;
in1 >> num11;
in1.close();
int randomnum1;
randomnum1 = num11+1;
ofstream out1(iidname);
out1 << randomnum1;
out1.close();
ifstream in(iidname);
int num1;
in >> num1;
in.close();
int randomnum;
randomnum = num1;


//open file to start the billing
ofstream file;
char line [] = " Supermarket of RANCHI 

";
stringstream ss;
char path[ MAX_PATH ];
if (SHGetFolderPathA( NULL, CSIDL_PERSONAL, NULL, 0, path ) != S_OK)
{
cout << “”;
}
else
{
cout << " ";
}
stringstream pathss; //path string streamer
string s;
pathss << path;
pathss >> s;
string billpath=s + “\CashMemoBills”;
mkdir( billpath.c_str() );
ss << path << “\CashMemobills\bill” << randomnum << “.cmb”;
string filename = ss.str();
cout << path;
file.open(filename); //ios::out | ios::trunc
file << line << endl;
file << " ################# INVOICE GENERATED SUCCESSFULLY #################

";
file << "
ID | PRODUCT NAME | RATE (INR) | PRODUCT QUANTITY | PRODUCT TALLY

";
//temporary end of file to start the loop
cout << "

################# INVOICE GENERATED SUCCESSFULLY #################

";
cout << "
ID | PRODUCT NAME | RATE (INR) | QUANTITY | TALLY

";
for(x=1;x<=totalitems;x++){
strupname=name[x].length();
spreq=maxlenall-strupname;
//loop started
int i;
file << " ";
file << x;
file << " ";
file << name[x];
for(i=0;i<=spreq;i++){
//loop for spaces
file << " ";
}
file << “”;
file << rate[x];
file << " ";
file << quantity[x];
file << " ";
file << cost[x];
file << "
";
cout << " " << x << " " << name[x] << “”;
for(i=0;i<=spreq;i++){
//loop for spaces
cout << " ";
}
cout << rate[x] << " " << quantity[x] << " " << cost[x] << "
";
}
//end of loop
file << "
Total is ";
file << total;
file << "

";
file << DATE;
file << " ";
file << TIME;
file << " “;
file << " Invoice ID : #”;
file << randomnum;

//close the file
file.close();
cout << "
 	 			 Total is " << total << "

";
cout << " " << DATE << " " << TIME << " " << “Invoice ID : #”;
cout << randomnum;
cout << "
";
cout << "

Invoice has been generated and saved as bill";
cout << randomnum;
cout << ".cmb.
Please print the text file saved in documents folder.

Press any key to continue “;
string sys1 = “notepad.exe”;
string s3 = sys1+” "+filename;
system(s3.c_str());
getch();
system(“cls”);
header();
/*if(exitcmd==“N” || exitcmd==“n”)
{
cout << "

";
newmemo();
}
else if(exitcmd==“O” || exitcmd==“o”)
{
cout << "

";
openmemo();
}
else{
exit(EXIT_SUCCESS);
}*/
}

//*******************************************
//OPENMEMO FUNCTION
//*******************************************

void openmemo(){
cout << " Enter the invoice id : ";
long memoid;
cin >> memoid;
char path2[ MAX_PATH ];
if (SHGetFolderPathA( NULL, CSIDL_PERSONAL, NULL, 0, path2 ) != S_OK)
{
cout << “”;
}
else
{
cout << " ";
}
stringstream pathss2; //path string streamer
string s2;
pathss2 << path2;
pathss2 >> s2;
string billpath2=s2 + “\CashMemoBills”;
stringstream ss2;
ss2 << path2 << “\CashMemobills\bill” << memoid << “.cmb”;
string memofile = ss2.str();
FILE *file2;
int file1_exists;
const char * filename2=memofile.c_str();
file2=fopen(filename2,“r”);
if (file2==NULL){
cout << "
No such invoices found with id " << memoid << ". Please try again…

";
	header();
}
else{
	cout << "

";
string output;
ifstream infile;
infile.open (memofile);
while (infile)
{
cout << output << endl;
getline(infile, output, ‘$’); //likely only need 1 of these
}
infile.close();

	cout << "

Press any key to continue
";
getch();
system(“cls”);
header();
/* if(exitcmd==“N” || exitcmd==“n”)
{
cout << "

";
newmemo();
}
else if(exitcmd==“O” || exitcmd==“o”)
{
cout << "

";
openmemo();
}

	else{exit(EXIT_SUCCESS);}*/
}

}

void Del(){

cout<<"

Enter invoice id to delete file records
";
long memid;
cin>>memid;
char path3[ MAX_PATH ];

if(SHGetFolderPathA(NULL,CSIDL_PERSONAL,NULL,0,path3)!=S_OK)
{
cout<<"";
}
else{
cout<<" ";
}

stringstream pathss3;
string s3;
pathss3<<path3;
pathss3>>s3;

string billpath3=s3 + "\\CashMemoBills";
stringstream ss3;
ss3 << path3 << "\\CashMemobills\\bill" << memid << ".cmb";
string memofile = ss3.str();
FILE *file2;
int file1_exists;
const char * filename3=memofile.c_str();
file2=fopen(filename3,"r");
if (file2==NULL){
	cout << "	

No such invoices found with id " << memid << ". Please try again…

";
	header();
}
else{
	cout << "

";
string output;
ifstream infile;
infile.open (memofile);
while (infile)
{

	  delete(filename3);
    }
    infile.close();
	
	cout << "

Press any key to continue
";
getch();
system(“cls”);
header();
/* if(exitcmd==“N” || exitcmd==“n”)
{
cout << "

";
newmemo();
}
else if(exitcmd==“O” || exitcmd==“o”)
{
cout << "

";
openmemo();
}

	else{exit(EXIT_SUCCESS);}*/
}

}

@sidstar

Please read this thread before posting your question:

http://discuss.codechef.com/questions/54561/how-to-ask-for-help