C++(Payroll Program)

Discussion in 'C++' started by Shayaan_Mustafa, Dec 28, 2010.

  1. Shayaan_Mustafa

    Shayaan_Mustafa New Member

    Joined:
    Dec 25, 2010
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Still a student.
    Location:
    Karachi
    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.
     
    Last edited by a moderator: Dec 30, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice