Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

PLEASE help me out of this..

0 votes
asked Jun 30, 2018 by Stuti Vasudev (140 points)
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int sc;

struct emp
{
    int idno;
    char name[15];
    char rank[15];
    int age;
    int bp;
    int bonus;
    int allw;
    int tax;
    int t;
    int np;

}s[10];

void title()
{
    system("cls");
    printf("\n\t\t\t_______________________________________________________");
    printf("\n\n\n\t\t\t\t    <<<<   INFOTECH  ORION   >>>>");
    printf("\n\n\t\t\t_______________________________________________________");
}

void menu()
{
    printf("\n\n\n\t1) ADD EMPLOYEE.");
    printf("\n\n\t2) CREATE SALARY.");
    printf("\n\n\t3) VIEW SALARY SLIP.");
    printf("\n\n\t4) EXIT.");
}

void addEmployee()
{

        int idno;
    char rank;
        title();
        printf("\n\n");
        printf("\nEnter Employee's name    :  ");
        scanf("%s",&s[sc].name);
        printf("\n\nEnter Employee's Rank   ..(M/S/E/A)   :  ");
        fflush(stdin);
        scanf("%c",&rank);
printf("\n\n\n");

                            if((rank=='s')||(rank=='S'))
                            {
                                s[sc].bp=30000;
                                s[sc].bonus=6000;
                                    printf("Basic pay  : %d\n\nBonus is  :  %d",s[sc].bp,s[sc].bonus);
                            }
                            else if((rank=='m')||(rank=='M'))
                            {
                                s[sc].bp=28000;
                                s[sc].bonus=5600;
                                    printf("Basic pay  : %d\n\nBonus is  :  %d",s[sc].bp,s[sc].bonus);
                            }
                            else if((rank=='e')||(rank=='E'))
                                {
                                s[sc].bp=25000;
                                s[sc].bonus=5000;
                                    printf("Basic pay  : %d\n\nBonus is  :  %d",s[sc].bp,s[sc].bonus);
                            }
                            else if((rank=='a')||(rank=='A'))
                            {
                                s[sc].bp=20000;
                                s[sc].bonus=4500;
                                        printf("Basic pay  : %d\n\nBonus is  :  %d",s[sc].bp,s[sc].bonus);
                                    }

printf("\n\n");
        printf("\nEnter age                       :  ");
                fflush(stdin);
        scanf("%d",&s[sc].age);

        {
            idno=sc+156783001;
            s[sc].idno=idno;
            printf("\n\nEmployee Identity Number is  : CW%d",idno);
            sc++;

        }
    getch();
}

void createSalary()
{
        s[sc].allw=6000;
        s[sc].t=s[sc].bp+s[sc].bonus+s[sc].allw;
        s[sc].tax=s[sc].t/5;
        s[sc].np=s[sc].t-s[sc].tax;

    printf("Salary slip created..!!!");
    getch();
}

void viewSalary()
{
int i;
title();
printf("\n\n");
printf("**************************************************************************************************");
printf("\n\tS.NO.   ID NO.    NAME   RANK  AGE   BP   ALLW   TOTAL   TAX DED.      NET PAY");
printf("\n**************************************************************************************************");
for(i=0;i<sc;i++)
{
    printf("\n\t %d    %10d  %-12s    %c    %3d  %7d %5d  %7d  %5d %  %7d",i+1,s[sc].idno,s[sc].name,s[sc].rank,s[sc].age,s[sc].bp,s[sc].allw,s[sc].t,s[sc].tax,s[sc].np);
}
getch();
}

int main()
{
                    int op=0,i;
                    sc=0;
                    FILE *fp5,*fp6;
                    struct emp temp;
                    fp5=fopen("EMPLOYEE.txt","wb");
                    fp6=fopen("SALARY.txt","wb");
                    fread(&sc,sizeof(sc),1,fp6);
                        for (i=0;i<sc;i++)
                                {
                                    fread(&temp,sizeof(temp),1,fp5);
                                    s[i]=temp;
                                }
                                fclose(fp5);
                                fclose(fp6);

                            while (op != 4)
                            {
                                            title();
                                            menu();
                                            printf("\n\n\n\t\tEnter any option  (1...........4)  :  ");
                                            scanf("%d",&op);
                                            switch(op)
                                            {
                                                            case 1:addEmployee();
                                                            break;
                                                            case 2:createSalary();
                                                            break;
                                                            case 3:viewSalary();
                                                            break;
                                            }
                            }
                    fp5=fopen("EMPLOYEE.txt","rb");
                    fp6=fopen("SALARY.txt","rb");
                    fread(&sc,sizeof(sc),1,fp6);

                    for (i=0;i<sc;i++)
                    {
                        fread(&temp,sizeof(temp),1,fp5);
                        s[i]=temp;
                    }
                    fclose(fp5);
                    fclose(fp6);

printf("\n\n\n\n\n\n\n\n\n");

fp5=fopen("EMPLOYEE.txt","wb");
    fp6=fopen("SALARY.txt","wb");
    fwrite(&sc,sizeof(sc),1,fp6);

    for (i=0;i<sc;i++)
    {
        s[i]=temp;
        fwrite(&temp,sizeof(temp),1,fp5);
    }
    fclose(fp5);
    fclose(fp6);
return 0;
}

2 Answers

0 votes
answered Jul 1, 2018 by anonymous
Whats your query exactly with this source code?
commented Jul 1, 2018 by anonymous
I want to print the salary slips of the 10 employees entered by me ..
you may compile this program and then run it, then
option 1 will add the names and information ,option 2 will create the data in file management,but when I press option 3,there is some problem in the data which is represented by the program,...I guess,the data represented is in the Binary format..
now PLEASE help me out of this...
commented Jul 13, 2018 by vtlev (100 points)
for the printf statement below:
 printf("\n\t %d    %10d  %-12s    %c    %3d  %7d %5d  %7d  %5d %  %7d",i+1,s[sc].idno,s[sc].name,s[sc].rank,s[sc].age,s[sc].bp,s[sc].allw,s[sc].t,s[sc].tax,s[sc].np);

you want to replace all [sc] with [i]
0 votes
answered Jul 13, 2018 by sambhavi devi tadi
you must place __fpurge() function for clearing the buffer before reading the input

that means before scanf you place that function which is present in stdlib library.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...