By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

can you please locate where is the error in my code?

P: 2

#include<stdio.h>
#include<conio.h>


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


FILE*source,*read;
void update();
void report();
void bye();
void maintenance();
void payslip();
void add();
void edit();
void menu();

FILE *fp;
char name[30],lastname[30];
char h,code,hrs,rate;
int choice;

main()
{
clrscr();
{
gotoxy(17,10);printf("WELCOME to Payroll System of");
delay(200);
}

gotoxy(6,13);printf(" ");
gotoxy(6,14);printf(" ");
gotoxy(6,15);printf(" ");
gotoxy(6,16);printf(" ");
gotoxy(6,17);printf(" ");
gotoxy(6,18);printf(" ");


// gotoxy(6,20);cprintf("");
h=getch();
gotoxy(23,21);system("pause");
while(h=='y');
main();



getch();
return 0;
}

void menu()
{
clrscr();


gotoxy(5,6);cprintf( "˻");
gotoxy(5,7);cprintf( " EDEECA ");
gotoxy(5,8);cprintf( "͹");
gotoxy(5,9);cprintf( " ");
gotoxy(5,10);cprintf(" [1] Report ");
gotoxy(5,11);cprintf(" ");
gotoxy(5,12);cprintf("ͼ");

gotoxy(23,6);cprintf( "˻");
gotoxy(23,7);cprintf( " EDEECA ");
gotoxy(23,8);cprintf( "͹");
gotoxy(23,9);cprintf( " ");
gotoxy(23,10);cprintf(" [2] Pay Slip ");
gotoxy(23,11);cprintf(" ");
gotoxy(23,12);cprintf("ͼ");

gotoxy(41,6);cprintf( "˻");
gotoxy(41,7);cprintf( " EDEECA ");
gotoxy(41,8);cprintf( "͹");
gotoxy(41,9);cprintf( " ");
gotoxy(41,10);cprintf(" [3] Update ");
gotoxy(41,11);cprintf(" ");
gotoxy(41,12);cprintf("ͼ");

gotoxy(59,6);cprintf( "˻");
gotoxy(59,7);cprintf( " EDEECA ");
gotoxy(59,8);cprintf( "͹");
gotoxy(59,9);cprintf( " ");
gotoxy(59,10);cprintf(" [4] Maintenace ");
gotoxy(59,11);cprintf(" ");
gotoxy(59,12);cprintf("ͼ");

gotoxy(32,14);cprintf("˻");
gotoxy(32,15);cprintf(" EDEECA ");
gotoxy(32,16);cprintf("͹");
gotoxy(32,17);cprintf(" ");
gotoxy(32,18);cprintf(" [5] Exit ");
gotoxy(32,19);cprintf(" ");
gotoxy(32,20);cprintf("ͼ");



gotoxy(29,22);cprintf("Choice: ");
scanf("%d",&choice);

switch(choice)
{
case 1:{
report();
}
case 2:{
payslip();
}
case 3:{
update();
}
//case 4:{
// maintenance();
// }
case 5:{
bye();
}

// getch();
}


void report()
{

char timein[5];
char timeout[5];
char in_hour[3];
char out_hour[3];
char in_min[3];
char out_min[3];
float gross_pay;

char *days[5]={"Monday","Tuesday","Wednesday","Thursday","Frida y"};

clrscr();


read=fopen("rose.txt","a+");

for(int day=0;day<5;day++)
{
if(day==0)
{
fprintf(read,"%s,",code);

gotoxy(12,26);cprintf("Enter time-in for %s : ",days[0]);
scanf("%s",&timein);
gotoxy(12,27);cprintf("Enter time-out for %s : ",days[0]);
scanf("%s",&timeout);
}
if(day==1)
{
gotoxy(12,29);cprintf("Enter time-in for %s : ",days[1]);
scanf("%s",&timein);
gotoxy(12,30);cprintf("Enter time-out for %s : ",days[1]);
scanf("%s",&timeout);
}
if(day==2)
{
gotoxy(12,32);cprintf("Enter time-in for %s: ",days[2]);
scanf("%s",&timein);
gotoxy(12,33);cprintf("Enter time-out for %s: ",days[2]);
scanf("%s",&timeout);
}
if(day==3)
{
gotoxy(12,35);cprintf("Enter time-in for %s : ",days[3]);
scanf("%s",&timein);
gotoxy(12,36);cprintf("Enter time-out for %s : ",days[3]);
scanf("%s",&timeout);
}
if(day==4)
{
gotoxy(12,38);cprintf("Enter time-in for %s : ",days[4]);
scanf("%s",&timein);
gotoxy(12,39);cprintf("Enter time-out for %s : ",days[4]);
scanf("%s",&timeout);
}
}


for(int i=0;i<2;i++)

in_hour[i]=timein[i];
in_min[i]=timein[i+3];
out_hour[i]=timeout[i];
out_min[i]=timeout[i+3];

float conv_outmin;
conv_outmin=atof(out_min);
if(conv_outmin>0){
if(conv_outmin<15){
conv_outmin=0;}}

float conv_inmin,conv_inhour;
conv_inmin=atof(in_min);
conv_inhour=atof(in_hour);
if(conv_inhour<=7){
if(conv_inhour>0){
conv_inhour=8;}
conv_inmin=0;}

float total_timein=0,total_timeout=0;
total_timein=conv_inhour+conv_inmin/60;
total_timeout=atof(timeout)+conv_outmin/60;

float total_time=total_timeout-total_timein;

if(total_time>4)
total_time=total_time-1;

hrs=hrs+total_time;

{

fprintf(read,"%s %s,\n",timein,timeout);

}


gotoxy(12,45);cprintf("Total hours present : %.2f",hrs);
{
gross_pay=(rate/8)*hrs;
gotoxy(12,47);cprintf("Gross Salary : %.2f",gross_pay);
gotoxy(12,49);cprintf("------------------------------------------------------");
}



fclose(read);

}


void payslip()
{
clrscr();
if((fp=fopen("edeeca.txt","r"))==NULL)
{
cprintf("Error opening student.txt\n");
}
else
{
cprintf("Names int file are: \n\n");
while(!feof(fp))
{
fflush(stdin);
fscanf(fp,"%s %s",&lastname,&name);
fflush(stdin);
cprintf("\n %s %s\n",lastname,name);
}
system("pause");
main();
}
}

void update()
{
char up;

clrscr();
gotoxy(5,6);cprintf( "˻");
gotoxy(5,7);cprintf( " EDEECA ");
gotoxy(5,8);cprintf( "͹");
gotoxy(5,9);cprintf( " ");
gotoxy(5,10);cprintf(" [1] Add Data ");
gotoxy(5,11);cprintf(" ");
gotoxy(5,12);cprintf("ͼ");

gotoxy(23,6);cprintf( "˻");
gotoxy(23,7);cprintf( " EDEECA ");
gotoxy(23,8);cprintf( "͹");
gotoxy(23,9);cprintf( " ");
gotoxy(23,10);cprintf(" [2] Edit Data ");
gotoxy(23,11);cprintf(" ");
gotoxy(23,12);cprintf("ͼ");

gotoxy(10,25);printf("Enter your choice:");
scanf("%c",&up);

switch(up)
{
case 1:
// {
// add();
// }
//case 2:
// {
// edit();
// }
//}
}

void add()

{

do{


if((fp=fopen("studgie.txt","a+"))==NULL)

{
cprintf("Error opening student.txt\n");
}
else
{
fflush(stdin);
gotoxy(23,12);cprintf("Enter complete name: ");
fflush(stdin);
gotoxy(23,14);scanf("%s %s",&lastname,&name);
gotoxy(23,16);fprintf(fp,"%s %s\n",lastname,name);

fclose(fp);
}
gotoxy(23,18);cprintf("Add another data?[y/n]");
h=getch();
gotoxy(23,21);system("pause");
}while(h=='y');
main();
} }

//void edit()
//{






void bye()
{
clrscr();

gotoxy(24,14);printf(" ");
gotoxy(24,15);printf(" ");
gotoxy(24,16);printf(" ");
gotoxy(24,17);printf(" ");
gotoxy(24,18);printf(" ");
gotoxy(24,19);printf(" ");

//getch();
}}
[/center]
[/left][/left]
Sep 14 '10 #1
Share this Question
Share on Google+
2 Replies


P: 2
can you please..
Sep 14 '10 #2

100+
P: 542
What error, compiling, run time, logic?
Where is the output unexpected?
Expand|Select|Wrap|Line Numbers
  1. Also please enclose your code in code tags like this by selecting and pressing #
Sep 14 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.