Hello, currently I'm working on my institute project. i've got some problem with me float data, when i enter the basic salary at the time of adding new employee, its not saving into my output file [data.txt] also not shown up when i search. also i got same problem in my entire float data.

please somebody help me to finish this :)

here is my code :

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#include <string.h>

struct employ
{
 char fname[25];
 char lname[25];
 char gender[25];
 char employment[30];
 char address[30];
 char months[15];
 char mobile[30];
 int EMP;
 int OTH;
 float bsalary;
 float EPF;
 float ETF;
 float OTR;
 float OTA;
 float nsalary;
};

char answer;


struct employ employ_rec;
void main_menu(void);
void emplomanag(void);
void printpayslp(void);
void printpayreport(void);
void addnemp(void);
void modifynemploy(void);
void deletenemploy(void);
void searchnemploy(void);
void design(void);
void ex(void);

FILE *femploy;
FILE *temp;
FILE *temp1;
FILE *data;


//*PASSWORD MENU

void main(void)
{
int User_name, Password, Valid, Try=1;
 
    textbackground(BLUE);
    textcolor(WHITE);
do
{
	design();

	gotoxy(29,22);
	printf("Enter User Name: ");
	scanf("%i",&User_name);
	
	gotoxy(29,24);
	printf("Enter password : ");
	scanf("%i",&Password);
	
	if(User_name!=1||Password!=1)
{
	gotoxy(30,19);
	printf("Invalid");

	if(User_name!=1)
{
	printf(" User name!");
}

	if(Password!=1)
{
	printf(" Password!");
}
	getch();
	gotoxy(30,15);
	clreol();
	gotoxy(30,17);
	clreol();
	gotoxy(30,19);
	clreol();

	Valid=0;
	Try+=1;
}

	else
	Valid=1;
}

	while(!Valid&&Try<=3);
	if(Try>3)
{
	gotoxy(30,19);
	printf("Maximum 3 try only!");
}

	else
{
	gotoxy(30,19);
	printf("Access approved !");
	getch();

	main_menu();
}
}



//*PAY ROLL MAIN MENU

void main_menu(void)
{
	int choice;
    float a,b,c;

	design();

  do
{
    gotoxy(32,3);
    textcolor(WHITE);
    cprintf("ABC INTERNATIONAL");

    gotoxy(33,5);
    cprintf("PAY ROLL SYSTEM");

    textcolor(WHITE);
    gotoxy(6,7);
    cprintf("*********************************************************************** ");

	gotoxy(30,8);
	textcolor(YELLOW);
{
	gotoxy(10,14);
    printf("1.Employee Management");
    gotoxy(10,18);
    printf("2.Print Pay Slip");
    gotoxy(10,22);
    printf("3.Print Pay Report");
    gotoxy(10,26);
    printf("4.Exit");
}

	gotoxy(10,30);
	printf("Enter your Choice[1-4]: ");
	scanf("%i",&choice);

	switch(choice)
{
	case 1:
    emplomanag();
    break;

    case 2:
    printpayslp();
    break;

    case 3:
    printpayreport();
    break;

    case 4:
    gotoxy(10,40);
    printf("Thank you\n");
    ex();
    getch();
    clrscr();
    break;

    default:
    clrscr();
    design();
    gotoxy(18,44);
    printf("Invalid Choice entered! Please Re-enter[1-4]");
}
}
    while((choice<1)||(choice>4));
}




//*SYSTEM DESIGN AREA


void design(void)
{
	char a,b,c;
	clrscr();

	gotoxy(5,3);
	for(a=0; a<72; a++)
	printf("*");
	gotoxy(5,3);
	for(b=0; b<45; b++)
	printf("\n    *\t\t\t\t\t\t\t\t\t   *");
	gotoxy(5,48);
	for(c=0; c<72; c++)
	printf("*");
}


//*EMPLOYEE MANAGEMENT MENU

void emplomanag(void)
{
	char c,answer;
	int valid, choice;
	clrscr();
    design();

	gotoxy(25,3);
	textcolor(WHITE);
	cprintf("ABC INT PAY ROLL SYSTEM");

	gotoxy(30,6);
	textcolor(YELLOW);
	cprintf("\nEMPLOYEE MANAGEMENT");

	gotoxy(10,14);
	printf("1.Add an Employee");
	gotoxy(10,18);
	printf("2.Modify Employee Details");
	gotoxy(10,22);
	printf("3.Delete an Employee");
	gotoxy(10,26);
	printf("4.Search an Employee");
	gotoxy(10,30);
	printf("5.Go Back");

	gotoxy(10,34);
	printf("Enter your Choice[1-5]: ");
	scanf("%i",&choice);

	switch(choice)
{
	case 1:
    addnemp();
    break;

    case 2:
    modifynemploy();
    break;

    case 3:
    deletenemploy();
    break;

    case 4:
    searchnemploy();
    break;

    case 5:
    gotoxy(10,40);
    main_menu();
    getch();
    clrscr();
    break;

    default:
    clrscr();
    design();
    gotoxy(18,44);
	printf("Invalid Choice entered! Please Re-enter[1-4]");
}
    while((choice<1)||(choice>5));
}



//*EMPLOYEE ADD MENU

void addnemp(void)
{
	char c,answer;
	int valid;
	do
{
	clrscr();
	design();

	gotoxy(25,3);
	textcolor(WHITE);
	cprintf("ABC INT PAY ROALL SYSTEM");

	gotoxy(30,6);
	textcolor(YELLOW);
	cprintf("\nAdd Employee");

	gotoxy(20,10);
	if((femploy=fopen("C:\\data.txt","a+"))==NULL)
{
	printf("Cannot open file\n");
	exit(EXIT_FAILURE);
}

	gotoxy(10,10);
	printf("   EMP No: ");
	scanf("%i",&employ_rec.EMP);

	gotoxy(10,12);
	printf("1. Employee First Name: ");
	fflush(stdin);
	gets(employ_rec.fname);

	gotoxy(10,15);
	printf("2. Employee Last Name: ");
	fflush(stdin);
	gets(employ_rec.lname);

	gotoxy(10,18);
	printf("3. Gender : ");
	fflush(stdin);
	gets(employ_rec.gender);

	gotoxy(10,21);
	printf("4. Employee Address : ");
	fflush(stdin);
	gets(employ_rec.address);

	gotoxy(10,24);
	printf("5. Employee Contact No : ");
	fflush(stdin);
	gets(employ_rec.mobile);

	gotoxy(10,27);
	printf("6. Employment : ");
	fflush(stdin);
	gets(employ_rec.employment);

	gotoxy(10,30);
	printf("7. Employee Basi Salary : ");
	fflush(stdin);
	scanf("%f",employ_rec.bsalary);

	fwrite(&employ_rec, sizeof employ_rec, 1, femploy);

	fclose(femploy);

	gotoxy(15,44);
	printf("Do you want to add another employ  [Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);

}
    while(answer=='Y'||answer=='y');

    emplomanag();
}


//*PAY SLIP FORM

void printpayslp(void)
{
     char c,answer;
     int valid, target, found=0;
do
{
     clrscr();
     design();

     gotoxy(25,3);
     textcolor(WHITE);
     cprintf("ABC INT PAY ROALL SYSTEM");

     gotoxy(30,6);
     textcolor(YELLOW);
     cprintf("\nPay Slip");

     gotoxy(20,10);
     if((femploy=fopen("C:\\data.txt","a+"))==NULL)
{
     printf("Data Not Found\n");
     exit(EXIT_FAILURE);
     getch();
}
else
{

     gotoxy(10,9);
     printf("Enter EMP No : ");
     fflush(stdin);
     scanf("%i",&target);

     while(fread(&employ_rec,sizeof employ_rec,1,femploy)==1)
{
     if (target!=employ_rec.EMP)
	 fwrite(&employ_rec,sizeof employ_rec,1, femploy);

     else
{
     found=1;
     clrscr();
      design();

     gotoxy(10,12);
     printf("Month : ");
     fflush(stdin);
     gets(employ_rec.months);

     gotoxy(10,17);
     printf("Basic Salary : %.2f",employ_rec.bsalary);

     gotoxy(10,21);
     employ_rec.EPF=((0.08)/100);
     printf("EPF : %.2f",employ_rec.EPF);

     gotoxy(10,24);
     employ_rec.ETF=3;
     printf("ETF : %.2f",employ_rec.ETF);

     gotoxy(10,27);
     printf("Over Time Hours : ");
     fflush(stdin);
     scanf("%i", &employ_rec.OTH);

     gotoxy(10,30);
     printf("Over Time Rate : ");
     fflush(stdin);
     scanf("%f", &employ_rec.OTR);

     gotoxy(10,33);
     employ_rec.OTA=employ_rec.OTR*employ_rec.OTH;
     printf("Over Time Amount : %.2f", employ_rec.OTA);

     gotoxy(10,37);
     employ_rec.nsalary=((employ_rec.OTA+employ_rec.ETF)-employ_rec.EPF);
     printf("Net Salary : %.2f",employ_rec.nsalary);
     
////////
    fwrite(&employ_rec, sizeof employ_rec, 1, femploy);

    gotoxy(20,44);
    printf("The data has been saved !");
}
}
    if(!found)
{  
    gotoxy(29,20);
    printf("Data not found!\n");
    getch();
}
}
    fclose(femploy);
	
    gotoxy(15,44);
	printf("Do you want to pay for another employ  [Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);
	
}
    while(answer=='Y'||answer=='y');
    
    main_menu();    
 
}


////////////////////////////////////////////////////////////////////
//*PRINT PAY REPORT

void printpayreport(void)
{
	do
{
	char c;
	char target[40];
	int found=0;
	clrscr();
	design();

	gotoxy(25,3);
    textcolor(WHITE);
    cprintf("ABC INT PAY ROLL SYSTEM");

    gotoxy(30,6);
    textcolor(YELLOW);
    cprintf("Pay Report");

	gotoxy(30,10);

    if((femploy=fopen("C:\\data.txt","r"))==NULL)
{
    printf("Database is empty!");
	getch();
}
    else
{
    gotoxy(26,9);
    printf("Enter Month [First 3 Latters] : ");
    fflush(stdin);
    gets(target);

    while(fread(&employ_rec,sizeof employ_rec,1,femploy)==1)
{
    if(strcmp(target,employ_rec.months)==0)
    found=1;
}
    if(found)
{
    gotoxy(10,10);
    printf("EMP No \t\t\tBasic Salary \t\t\tEPF \t\tETF \t\tOT Amount \t\t\tNet Salary");

    gotoxy(10,12);
    printf("%i \t\t\t%.2f \t\t\t%s \t\t%.2f \t\t%.2f \t\t\t%.2f",employ_rec.EMP, employ_rec.bsalary, employ_rec.EPF, employ_rec.ETF, employ_rec.OTA, employ_rec.nsalary);

    gotoxy(10,15);
    printf("%i \t\t\t%.2f \t\t\t%s \t\t%.2f \t\t%.2f \t\t\t%.2f",employ_rec.EMP, employ_rec.bsalary, employ_rec.EPF, employ_rec.ETF, employ_rec.OTA, employ_rec.nsalary);

//////////
}
    else
{
    gotoxy(33,21);
    printf("Data not found! ");
}
}
	fclose(femploy);

	gotoxy(10,42);
	printf("Do you want to search another month[Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);
}
	while(answer=='Y'||answer=='y');

     main_menu();
}


//*SEARCH AN EMPLOYEE

void searchnemploy(void)
{
	do
{
	char c;
	char target[40];
	int found=0;
	clrscr();
	design();

	gotoxy(25,3);
    textcolor(WHITE);
    cprintf("ABC INT PAY ROLL SYSTEM");

    gotoxy(30,6);
    textcolor(YELLOW);
    cprintf("Search an Employee");

	gotoxy(30,10);

    if((femploy=fopen("C:\\data.txt","r"))==NULL)
{
    printf("Database is empty!");
	getch();
}
    else
{
    gotoxy(26,9);
    printf("Enter Employee Last Name : ");
    fflush(stdin);
    gets(target);

    while(fread(&employ_rec,sizeof employ_rec,1,femploy)==1)
{
    if(strcmp(target,employ_rec.lname)==0)
    found=1;
}
    if(found)
{

    gotoxy(10,10);
    printf("EMP No : %i",employ_rec.EMP);

    gotoxy(10,12);
    printf("1. Employee First Name : %s",employ_rec.fname);

    gotoxy(10,15);
    printf("2. Employee Last Name : %s",employ_rec.lname);

    gotoxy(10,18);
    printf("3. Gender : %s",employ_rec.gender);

    gotoxy(10,21);
    printf("4. Employee Address: %s",employ_rec.address);

    gotoxy(10,24);
    printf("5. Employee Contact No : %s",employ_rec.mobile);

    gotoxy(10,27);
    printf("6. Employment : %s",employ_rec.employment);

    gotoxy(10,30);

    printf("7. Basic Salary : %.2f",employ_rec.bsalary);

}
    else
{
    gotoxy(33,21);
    printf("Data not found! ");
}
}
	fclose(femploy);

	gotoxy(10,42);
	printf("Do you want to search another employ[Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);
}
	while(answer=='Y'||answer=='y');

	emplomanag();
}


//*MODIFY EMPLOYEE DETAILS

void modifynemploy(void)
{
	do
{
	char c;
	int traget,found=0;
	clrscr();
	design();

	gotoxy(25,3);
	textcolor(WHITE);
	cprintf("ABC INT PAY ROLL SYSTEM");

	gotoxy(30,6);
	cprintf("MODIFY EMPLOYEE DETAILS");

	temp=fopen("c:\\temp.txt","w");

	if((femploy=fopen("c:\\data.txt","a++"))==NULL)
{
	gotoxy(25,35);
	printf("File is Empty");
	getch();
}
	else
{
	gotoxy(27,9);
	printf("Enter employee EMP No : ");
	fflush(stdin);
	scanf("%i",&traget);

	while(fread(&employ_rec,sizeof employ_rec,1,femploy)==1)
{
	if (traget!=employ_rec.EMP)
	fwrite(&employ_rec,sizeof employ_rec,1,temp);

	else
{
	found=1;

	gotoxy(10,12);
	printf("1. Employee First Name : ");
	fflush(stdin);
	gets(employ_rec.fname);

	gotoxy(10,15);
	printf("2. Employee Last Name : ");
	fflush(stdin);
	gets(employ_rec.lname);

	gotoxy(10,18);
	printf("3. Gender : ");
	fflush(stdin);
	gets(employ_rec.gender);

	gotoxy(10,21);
	printf("4. Employee Address : ");
	fflush(stdin);
	gets(employ_rec.address);

	gotoxy(10,24);
	printf("5. Employee Contact No : ");
	fflush(stdin);
	gets(employ_rec.mobile);

	gotoxy(10,27);
	printf("6. Employment : ");
	fflush(stdin);
	gets(employ_rec.employment);

	gotoxy(10,30);
	printf("7. Employee Basic Salary : ");
	fflush(stdin);
	scanf("%f",employ_rec.bsalary);

	fwrite(&employ_rec,sizeof employ_rec,1,temp);
}
}

	if(!found)
{
	gotoxy(30,28);
	printf("Data not Found!\n");
	getch();
}
}

	fclose(femploy);
	fclose(temp);
	remove("c:\\data.txt");
	rename("c:\\temp.txt","c:\\data.txt");

	gotoxy(16,42);
	printf("Do you want to change another employ[Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);
}
	while(answer=='Y'||answer=='y');

	emplomanag();
}


//*DELETE AN EMPLOYEE

void deletenemploy(void)
{
    do
{   
    char c;
    int traget,found=0;;
    clrscr();
	design();

    gotoxy(25,3);
    textcolor(WHITE);
    cprintf("ABC INT PAY ROLL SYSTEM");
     
    gotoxy(30,6);
    textcolor(YELLOW);
    cprintf("Delete an Employee");

    temp1=fopen("c:\\temp1.txt","w");
    if((femploy=fopen("c:\\data.txt","r"))==NULL)
{
    printf("Data Not Found!");
    getch();
}
    else
{
    
    gotoxy(27,9);
    printf("Enter EMP No : ");
    fflush(stdin);
    scanf("%i",&traget);
    while(fread(&employ_rec,sizeof employ_rec,1,femploy)==1)
{
    if (traget!=employ_rec.EMP)
	fwrite(&employ_rec,sizeof employ_rec,1,temp1);

	else
{
    found=1;
    clrscr();

    gotoxy(10,10);
    printf("EMP No : %i",employ_rec.EMP);

    gotoxy(10,12);
    printf("1. Employee First Name : %s",employ_rec.fname);

    gotoxy(10,15);
    printf("2. Employee Last Name : %s",employ_rec.lname);

    gotoxy(10,18);
    printf("3. Gender : %s",employ_rec.gender);

    gotoxy(10,21);
    printf("4. Employee Address: %s",employ_rec.address);

    gotoxy(10,24);
    printf("5. Employee Contact No : %s",employ_rec.mobile);

    gotoxy(10,27);
    printf("6. Employment : %s",employ_rec.employment);

    gotoxy(10,30);
    printf("7. Employee Basic Salary : %.2f",employ_rec.bsalary);
    getch();
}
}
    if(!found)
{    
    gotoxy(29,20);
    printf("Data not found!\n");
    getch();
}
}

    fclose(femploy);
    fclose(temp1);
    remove("c:\\data.txt");
    rename("c:\\temp1.txt","c:\\data.txt");
     
    gotoxy(20,44);
    printf("The data has been deleted !");
    
    gotoxy(20,47);
	printf("Do you want to delete more emplyee [Y/N]:");
	fflush(stdin);
	scanf("%c",&answer);
}
    while(answer=='Y'||answer=='y');
     
    emplomanag();
}


//*SYSTEM EXIT MENU


void ex(void)
{
    int choice;
    clrscr();
    design();

    gotoxy(25,3);
    textcolor(WHITE);
    cprintf("ABC INT PAY ROLL SYSTEM");
     
    gotoxy(32,10);
    textcolor(YELLOW);
    cprintf("ABC International");
     
    gotoxy(35,14);
    cprintf("Exiting Menu");
    do
{
    gotoxy(12,22);
    printf("1.Back to main menu");

    gotoxy(12,28);
    printf("2.Exit system");
    gotoxy(10,22);

    gotoxy(12,34);
    printf("Enter your Choice:");
    scanf("%i",&choice);

    switch(choice)
{
    case 1:
	main_menu();
    break;

    case 2:
    gotoxy(25,40);
    printf("Thank you! Have a nice day");
    getch();
    break;

    default:
    design();
    gotoxy(28,44);
    printf("Invalid Choice");
}
}
    while((choice<1)||(choice>2));
}

there are 3 main steps, my problem is in 1.Employee Management. And I'm still working on 2. Print Pay Slip, 3.Print Pay Report.

sorry for my poor English!

Recommended Answers

All 5 Replies

I'm Using TurboC Compiler

Why is the username and password integer datatypes ?
Why have you used cprintf ?
Syntax of fwrite is wrong

Usually, I'd tell you fflush(stdin) is wrong. But since you are using a thirty year old compiler with functions that haven't existed since the mid-80's, I'll let it go this time. I hope you aren't learning on this compiler for a potential career. You will have to unlearn a great deal. cprintf() is the Turbo graphics version of printf()

commented: Wow, you made it through nearly 1K lines of TurboCrap +19

Thank you Guys!

fflush(stdin) is from output buffers, forces all data in the buffer to be written. that's why i still using. and my institute request to use CTurbo to finish this Project. im still stacked by same problem. please i hope you guys will help me :)

Thank you Guys!

fflush(stdin) is from output buffers, forces all data in the buffer to be written. that's why i still using.

Since when is stdin an output buffer? Where does it write to?

and my institute request to use CTurbo to finish this Project. im still stacked by same problem. please i hope you guys will help me :)

Sounds like you need to find an institute that will teach you programming... Real programming. Things have changed in the pas 30 years.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.