In: Computer Science
I dont know why it is not working
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
// Define Number of Employees "SIZE" to be 2
// Declare Struct Employee
/* main program */
#define SIZE 2
struct employee
{
int id;
int age;
double salary;
};
int main(void)
{
int option = 0, number = 0, count = 0;
struct Employee emp[SIZE] = { { 0 } };
// Declare a struct Employee array "emp" with SIZE elements
// and initialize all elements to zero
printf("---=== EMPLOYEE DATA ===---\n\n");
do
{
// Print the option list
printf("1. Display Employee Information\n");
printf("2. Add Employee\n");
printf("0. Exit\n\n");
printf("Please select from the above options: ");
// Capture input to option variable
scanf("%d", &option);
printf("\n");
switch (option)
{
case 0: // Exit the program
break;
case 1: // Display Employee Data
// @IN-LAB
printf("EMP ID EMP AGE EMP SALARY\n");
printf("====== ======= ==========\n");
for (number = 0; number < SIZE; number++)
{
if (emp[number].id > 0)
{
printf("%6d %9d %11.2lf\n", emp[number].id, emp[number].age, emp[number].salary);
}
}
printf("\n");
// Use "%6d%9d%11.2lf" formatting in a
// printf statement to display
// employee id, age and salary of
// all employees using a loop construct
// The loop construct will be run for SIZE times
// and will only display Employee data
// where the EmployeeID is > 0
break;
case 2: // Adding Employee
// @IN-LAB
printf("Adding Employee\n");
printf("===============\n");
count++;
if (count > SIZE) {
printf("ERROR!!! Maximum Number of Employees Reached\n\n");
}
else {
printf("Enter Employee ID: ");
scanf("%d", &emp[count - 1].id);
printf("Enter Employee Age: ");
scanf("%d", &emp[count - 1].age);
printf("Enter Employee Salary: ");
scanf("%lf", &emp[count - 1].salary);
printf("\n");
}
// Check for limits on the array and add employee
// data accordingly.
break;
default:
printf("ERROR: Incorrect Option: Try Again\n\n");
}
} while (option != 0);
printf("Exiting Employee Data Program. Good Bye!!!");
return 0;
}
//PROGRAM OUTPUT IS SHOW BELOW
/*
---=== EMPLOYEE DATA ===---
1. Display Employee Information
2. Add Employee
0. Exit
Please select from the above options: 2
Adding Employee
===============
Enter Employee ID: 111
Enter Employee Age: 34
Enter Employee Salary: 78980.88
1. Display Employee Information
2. Add Employee
0. Exit
Please select from the above options: 2
Adding Employee
===============
Enter Employee ID: 112
Enter Employee Age: 41
Enter Employee Salary: 65000
1. Display Employee Information
2. Add Employee
0. Exit
Please select from the above options: 2
Adding Employee
===============
ERROR!!! Maximum Number of Employees Reached
1. Display Employee Information
2. Add Employee
0. Exit
Please select from the above options: 1
EMP ID EMP AGE EMP SALARY
====== ======= ==========
111 34 78980.88
112 41 65000.00
1. Display Employee Information
2. Add Employee
0. Exit
Please select from the above options: 0
Exiting Employee Data Program. Good Bye!!!
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
// Define Number of Employees "SIZE" to be 2
// Declare Struct Employee
/* main program */
#define SIZE 2
// here it should be Employee not employee
struct Employee
{
int id;
int age;
double salary;
};
int main(void)
{
int option = 0, number = 0, count = 0;
struct Employee emp[SIZE];
// Declare a struct Employee array "emp" with SIZE elements
// and initialize all elements to zero
printf("---=== EMPLOYEE DATA ===---\n\n");
do
{
// Print the option list
printf("1. Display Employee Information\n");
printf("2. Add Employee\n");
printf("0. Exit\n\n");
printf("Please select from the above options: ");
// Capture input to option variable
scanf("%d", &option);
printf("\n");
switch (option)
{
case 0: // Exit the program
break;
case 1: // Display Employee Data
// @IN-LAB
printf("EMP ID EMP AGE EMP SALARY\n");
printf("====== ======= ==========\n");
for (number = 0; number < SIZE; number++)
{
if (emp[number].id > 0)
{
printf("%6d %9d %11.2lf\n", emp[number].id, emp[number].age, emp[number].salary);
}
}
printf("\n");
// Use "%6d%9d%11.2lf" formatting in a
// printf statement to display
// employee id, age and salary of
// all employees using a loop construct
// The loop construct will be run for SIZE times
// and will only display Employee data
// where the EmployeeID is > 0
break;
case 2: // Adding Employee
// @IN-LAB
printf("Adding Employee\n");
printf("===============\n");
count++;
if (count > SIZE) {
printf("ERROR!!! Maximum Number of Employees Reached\n\n");
}
else {
printf("Enter Employee ID: ");
scanf("%d", &emp[count - 1].id);
printf("Enter Employee Age: ");
scanf("%d", &emp[count - 1].age);
printf("Enter Employee Salary: ");
scanf("%lf", &emp[count - 1].salary);
printf("\n");
}
// Check for limits on the array and add employee
// data accordingly.
break;
default:
printf("ERROR: Incorrect Option: Try Again\n\n");
}
} while (option != 0);
printf("Exiting Employee Data Program. Good Bye!!!");
return 0;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME