PLEASE HELP I NEED TO PASS THIS HOMEWORK AND I ONLY HAVE 16 HRS BEFORE I SUBMIT IT AND I ALSO HAVE ANOTHER ASSIGNMENT ON MY ENGINEERING MATH, CALCULUS AND SOLID MENSURATION I DON'T HAVE ENOUGH TIME TO FINISH THIS PROGRAM PLS SOMEONE HELP ME WITH THIS THANKS IN ADVANCE

#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

Add a scanf for last name after the first name.

//...
    char name[20], lastname[20];
    printf("Employee Name:\t\t\t");
    scanf("%8s", &name);
    scanf("%8s", &lastname);
    //...
    printf("\n\tEmployee Name: %s %s\t\t", name, lastname);
    //...

You're trying to shove a first and a last name, into the same variable, name[]. That won't work.

You can fix it easily a few different ways:

char lastname[30];
char firstname[30];

and then scanf() for the lastname, and for the firstname[] (or lname and fname, whatever).

Or you can:

char name[30]; //30 is a little small for a two name size, try 50 or 60

//fgets() is safer and a more robust input function. It will not overflow.
fgets(name, sizeof(name), stdin); //get both names as one input

name[strlen(name)]='\0'; //overwrite the newline char that fgets() adds to the name

Since all your numerical variables are doubles, I'm puzzled why you cast a few of them to float, in the program. No need to do that.

main() in C and C++, ALWAYS should return an int:

int main(void) //is one correct way to call main 
{
  //your program in here
  //then
  return 0;   //indicating a normal program completion
}

Give that a try, and good luck with your classes. ;)

You're trying to shove a first and a last name, into the same variable, name[]. That won't work.

You can fix it easily a few different ways:
[snip]

char name[30]; //30 is a little small for a two name size, try 50 or 60

//fgets() is safer and a more robust input function. It will not overflow.
fgets(name, sizeof(name), stdin); //get both names as one input

name[strlen(name)]='\0'; //overwrite the newline char that fgets() adds to the name

Gee, just as I said in yout other thread! This one is closed.

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.