Hi! my dear all.
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class payroll
{
private:
char address[50];
float basic,allowence,deduction;
public:
void add(void);
};
void payroll::add(void)
{
clrscr();
int e_no,choice;
char name[50],ch;
payroll e;
cout<<"Enter Employe Number: ";cin>>e_no;
cout<<"Enter Employe Name: ";gets(name);
cout<<"Enter Employe's Address: ";gets(e.address);
cout<<"Enter Employe's Basic Salary: ";cin>>e.basic;
cout<<"Enter Employe's Allownce: ";cin>>e.allowence;
cout<<"Enter Deduction: ";cin>>e.deduction;
cout<<"\n\dfn1-> Save 2-> Cancel";cin>>choice;
if(choice==1)
{
FILE*fptr;
fptr=fopen("d:\\bank.dat","r+");
fwrite(&e,sizeof(e),1,fptr);
fclose(fptr);
}
else if(choice==2)
cout<<"Record Cancelled";
clrscr();
}
payroll emp;
void main(void)
{
clrscr();
char ch;
int choice;
cout<<"\n============main menu============";
cout<<"\n1 -> Add Record";
cout<<"\n2 -> List Record";
cout<<"\n3 -> Delete Record";
cout<<"\n4 -> Update Record";
cout<<"\nq -> Quit\n\n";
cin>>ch;
switch(ch)
{
case'1': emp.add();break;
case'q': break;
}
getch();
}
Here is my code.
I am trying to create a payroll of an employee. As you can see by code that I am yet able to create record just.
But after giving all information when I try to save my record by pressing 1, nothing happens and when I press 2 it should show a statement "Record canceled" but it is not.