Contoh aturcara Fail

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<iomanip.h>
#include<cstring.h>

void main()
{
int jumMH=0,jumEA=0,jumMZ=0,undi;
string nama,pemenang;
char respon;




fstream candidat;

candidat.open("D:candidate.dat",ios::out);

if(!candidat)
{
cout<<"fail tidak dapat di buka";
exit(1);
}

do
{
cout<<"\nsiapakah yang anda undi? ";
cin>>undi;

if(undi==1)
{
jumMH = jumMH + 1;
nama = "Mohd Hariz";
}
else if(undi==2)
{
jumEA = jumEA + 1;
nama = "Emir Adam";
}
else if(undi==3)
{
jumMZ = jumMZ + 1;
nama = "Mohd Azim";
}

candidat<<nama<<endl;
cin.ignore();
cout<<"adakah anda ingin teruskan: ";
cin>>respon;
}while(respon=='y'||respon=='Y');

cout<<"\njumlah Mohd Hariz ialah: "<<jumMH;
cout<<"\njumlah Emir Adam ialah: "<<jumEA;
cout<<"\njumlah Mohd azam ialah: "<<jumMZ;

if(jumMH>jumEA&&jumMH>jumMZ)
pemenang = "Mohd Hariz";
else if(jumEA>jumMH&&jumEA>jumMZ)
pemenang = "Emir Adam";
else if(jumMZ>jumMH&&jumMZ>jumEA)
pemenang = "Mohd Azim";
else
pemenang = "keputusan seri";

cout<<"\n\n---------------------------------------------------";
cout<<"\npemenang untuk jawatan presiden ialah: "<<pemenang;
cout<<"\n---------------------------------------------------";

candidat.close();
}