C PROGRAMMING HELP
the problem is i can prompt the user for input and collect input but when i use for loop to print out the stored value that was key in by the user it displays wrong output
this is the code.
#include<stdio.h>
#include<string.h>
int main()
{
int i;
struct employee
{
struct personal_info
{
char name[20];
char id[20];
char phone_number[12];
int startdate;
}p;
struct salary_info
{
double basic_salary;
double hours_worked;
}s;
struct net
{
double netIncome;
}n
}emp[5];
struct employee *ptr;
ptr = emp;
printf("\t\tEMPLOYEE PERSONAL DATA FORM\n\n");
for(i = 0; i < 5; i++)
{
printf("\t\t EMPLOYEE %d Record \n", i +1);
printf("Enter Name %d :", i + 1);
scanf(" %s", &emp[i].p.name);
printf("Enter ID %d :", i + 1);
scanf(" %s", &emp[i].p.id);
printf("Enter Phone Number %d :", i + 1);
scanf(" %s", &emp[i].p.phone_number);
printf("Enter Start Date %d :", i + 1);
scanf(" %d", &emp[i].p.startdate);
printf("Enter Basic Salary %d :", i + 1);
scanf(" %f", &emp[i].s.basic_salary);
printf("Enter Hours Worked %d :", i + 1);
scanf(" %d", &emp[i].s.hours_worked);
printf("\n");
printf("\n");
}
for(i = 0; i < 5; i++)
{
if(ptr->s.hours_worked <= 20)
{
ptr->n.netIncome = (ptr->s.hours_worked * 3.5)-(0.11+0.03);
}
else if(ptr->s.hours_worked > 20)
{
ptr->n.netIncome = ((ptr->s.hours_worked)* 4.2)-(0.11+0.03);
}
ptr++;
}
// SOME THING IS WRONG THIS FOR LOOP PLS I NEED HELP
printf("\t\t PRINTING OUT EMPLOYEE INFORMATION");
printf("\n\n\n");
for(i = 0; i < 5; i++)
{
printf("\t\t Employe number %d information", i+1);
printf("\n");
printf("\t\t Employee Basic Salary... %d", ptr->s.basic_salary);
printf("\n");
printf("\t\t Employee Hours Worked... %d", ptr->s.hours_worked);
printf("\n");
printf("\t\t Employee NetIncome... %d", ptr->n.netIncome);
ptr++;
}
return 0;
}
-
SoftwareGeek -
Thanks - 1 reply
{{ DiscussionBoard.errors[8778554].message }}-
softwarewarden -
Thanks
{{ DiscussionBoard.errors[8779673].message }} -
-