Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++(Payroll Program) (http://www.go4expert.com/forums/cpp-payroll-program-t24300/)

Shayaan_Mustafa 28Dec2010 20:33

C++(Payroll Program)
 
Hi! my dear all.
Hope all of you will be fine.
Code:

#include<iostream.h>
#include<stdlib.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.
I am using Turbo C++ IDE means just C++ not object oriented.


All times are GMT +5.5. The time now is 11:59.