Question

In: Computer Science

I dont know why it is not working #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> // Define Number of...

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!!!

*/

Solutions

Expert Solution

#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


Related Solutions

construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b...
construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b 6 #define t 6 double bmical(double w, double h){ double o; double bmi; o = pow(h,2); bmi = w/o; return bmi; } double maxheartrate(int num1, int age){ double mhr; mhr = num1 - age; return mhr; } double heartratereserve(double mhr, double rhr){ double hrr; hrr = mhr - rhr; return hrr; } double minrange(int hrr, int rhr){ double mirt; mirt = (hrr * 0.7)...
#include <stdio.h> #include <stdlib.h> #define K   1024 /** (2pts) * This problem is like p1, except...
#include <stdio.h> #include <stdlib.h> #define K   1024 /** (2pts) * This problem is like p1, except that you should read the number using scanf() * and the string to print using fgets() (up to 1024 characters.) Use "num: " as * the prompt for the number and "str: " as the prompt for the string. Keep in * mind that the newline that is entered will still be in the string when * printing it. NOTE: After the scanf() for...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int...
My current code that is not working correctly #include<stdio.h> #include<math.h> int main() { //variable declaration int a,b,c,D,n; double x1,x2; double realPart, imagPart; do { // this set of code blocks prompts a message to the user and then read the integer entered and stores it as an integer printf("Enter a value for a:\n"); scanf("%d",&a); printf("Enter a value for b:\n"); scanf("%d",&b); printf("Enter a value for c:\n"); scanf("%d",&c); printf("You entered the Equation \n"); printf("%dx^2%+dx%+d=0\n",a,b,c); D = b*b - 4*a*c;    if (D<0)...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I have random array [4,2,7,1,9,8,0]. Sort the array's index but cannot change the position of item in the array, if you copy the array to a new array, you also cannot change the item's position in array. The index now is[0,1,2,3,4,5,6] The output should be[6,3,1,0,2,5,4]
I have this exercise and i dont know how to do it DDB Corporation was formed...
I have this exercise and i dont know how to do it DDB Corporation was formed by twenty-four shareholders on January 1, 2017. The shareholders will be having their semi-annual meeting on September 28, 2018 to review the financial results for January 1 – June 30, 2018. As of January 1, 2018, the company has a retained deficit (this means the company incurred a net loss in 2017). The following are the unadjusted balances of DDB Corporation as of June...
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h>...
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h> int main() { int seed; // Taking seed value as input from the user printf("Enter a seed value (0 to quit): \n"); scanf("%d", &seed); // Running the loop until user enters 0 to quit // count array will count frequency of 0 , 1 , 2 ,3 int count[4]; for (int i = 0; i < 4; i++) count[i] = 0; while (seed !=...
#include <stdio.h> #include <cmath> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #pragma warning (disable : 4996) int...
#include <stdio.h> #include <cmath> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #pragma warning (disable : 4996) int main() {    const char* filename = "samples.coe"; const int N = 1024; FILE* file = fopen(filename, "w"); if (file == NULL) { perror("fopen"); } fprintf(file, "; These are 1024 sample values in range -1 to 1,\n"); fprintf(file, "; Sine Wave 0\n"); fprintf(file, "memory_initialization_radix = 10;\n"); fprintf(file, "memory_initialization_vector\n"); double values[N]; double delta = M_PI / (N - 1); for (int i = 0; i...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter between 8 to 60 inches: "); scanf("%d",&diameter); // if(diameter>60 || diameter<=8){ // printf("Error! invalid input"); // exit(0); // } // else{ // float radius = diameter/2; // float volume = (4/3)*PI*radius*radius*radius; // printf("%.2f",volume); // } //check through the while loop if it is valid or in valid while(diameter>60 || diameter<=8){ printf("Invalid input Enter again: "); scanf("%d",&diameter); }    //caluclate the volume of sphere float...
If want to apply the scholarship at college, but I dont know to introduce about myself....
If want to apply the scholarship at college, but I dont know to introduce about myself. Please help me, I will like and give good feedback! Thank you
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT