0

Please help me, I already made a programm it run good if i only input a first name but if i input first and last name it did'nt work properly
here is the program i made and the output of the program

PROGRAM

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

char a,name;
double x,y,z,b,c,d,late,ot,ot1,ot2,xin,wrk,grs,tax,phil,sss,td,net,net1;
main()
{
  char name[20];
  printf("Employee Name:\t\t\t");
  scanf("%8s", &name);
  printf("Number of hours work:\t\t");
  scanf("%lf", &x);
  printf("Extra hours work (OT):\t\t");
  scanf("%lf", &y);
  printf("Number of hours late(UT):\t");
  scanf("%lf", &z);
  printf("Rate per hour:\t\t\t");
  scanf("%lf", &b);
  printf("Food deduction:\t\t\t");
  scanf("%lf", &c);
  printf("Extra income:\t\t\t");
  scanf("%lf", &d);
  a=(char)name;
  printf("\n\tEmployee Name:  %s\t\t",name);
  scanf("%c", &name);
  late=(float)z*b;
  printf("\n\tUndertime pay:   %5.2lf\t\t",late);
  ot1=(float)b*0.04*y;
  ot2=(double)y*b;
  ot=(double) ot1+ot2;
  printf("\n\tOvertime pay:   %5.2lf\t\t",ot);
  xin=(float)d;
  printf("\n\tExtra income:    %5.2lf\t\t",xin);
  ot1=(float)b*0.04*y;
  ot2=(double)y*b;
  ot=(double) ot1+ot2;
  wrk=(double)x*b;
  grs=(double)ot+wrk;
  printf("\n\tGross pay:      %5.2lf\t\t\t",grs);
  ot1=(float)b*0.04*y;
  ot2=(double)y*b;
  ot=(double) ot1+ot2;
  wrk=(double)x*b;
  grs=(double)ot+wrk;
  tax=grs*.15;
  phil=grs*.025;
  sss=grs*.04;
  late=(double)z*b;
  td=(double)tax+phil+sss+c+late;
  net1=(double)grs-td;
  net=(double)net1+d;
  printf("\n\tNet pay:       %5.2lf\t\t\t",net);
  
  getch();
}

WHEN I INPUT ONLY FIRSTNAME ONLY IT WORKS PROPERLY

Employee Name: mark
Number of hours work: 240
Extrea hours work (OT): 52
Number of hours late(UT): 2
Rate per hour: 100
Food deduction: 300
Extra income: 1250

Employee Name: mark
Undertime pay: 200.00
Overtime pat: 5408.00
Extra income: 1250.00
Gross pay: 29408.00
Net pay: 23835.28


----------------------------------------------

BUT WHEN I INPUT BOTH FIRST AND LAST NAME THIS HAPPENED

Employee Name: mark gwapo
Number of hours work: Extrea hours work (OT): Number of hours
late(UT): Rate per hour: Food deduction:
Extra income:

Employee Name: mark
Undertime pay: 0.00
Overtime pat: 0.00
Extra income: 0.00
Gross pay: 0.00
Net pay: 0.00

Edited by WaltP: Added CODE Tags -- please use them

3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by WaltP
0

scanf("%8s", &name); //???
Think about the %8 for this line.

already change to another value or remove that 8 but i still got an error in output

0

scanf() cannot read two words easily. And it's only slightly less dangerous than gets() .

Look up fgets() . You will have to check the last character for \n and remove it, but it's safer and easily reads the entire line.

0

If you want two values, you will need to use two variables in the scanf.

scanf("%8s %8s", &strFirstName, &strLastName);

...or use gets()

0

If you want two values, you will need to use two variables in the scanf.

scanf("%8s %8s", &strFirstName, &strLastName);

...or use gets()

Never NEVER **NEVER** recommend gets() !!! Didn't you read the previous post? It's dangerous!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.