Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Execute the following coding segment and identify the errors in the program. Deb

ID: 2083331 • Letter: E

Question

Execute the following coding segment and identify the errors in the program. Debug the program and provide the correct version of the code. Note: The errors can be syntactical or logical.

Execute the following coding segment and identify the errors in the program. Debug the program and provide the correct version of the code. Note: The errors can be syntactical or logical.

#include k stdio.h employee structure definition struct employee unsigned int age, char gender; double hourly Salary int main(void) employee emp1; define one struct employee variable Store values in the empl emp1. age 20 emp1 gender 'M'; emp1 .hourly salary 10 printf ("%s%d emp1 age is: emp1.age printf ("%s%cIn", emp1 gender is emp1. gender); printf ("%s%. 2f ", emp1 hourly salary is emp1.hourlySalary) return 0

Explanation / Answer

Code:

#include<stdio.h>

//employee structure defination
struct employee
{
   unsigned int age;
   char gender;
   double hourlySalary;
}; // Semicolon is missing

int main(void)
{
   // struct keyword is missing
   struct employee emp1; // define one struct employee variable
                   // Store values in the empl
  
   emp1.age = 20;
   emp1.gender = 'M';
   emp1.hourlySalary = 10;
  
   printf ("%s%d ", "emp1 age is ",emp1.age);
   printf ("%s%c ", "emp1 gender is ",emp1.gender); // To display character %c is used
   printf ("%s%f ", "emp1 hourly salary is ",emp1.hourlySalary); // %f used for displaying the float or double variable

          
   return 0;
}

Mistakes:

1. Semicolon after structure defination

2. struct keyword before declaring the emp1 variable.

3.In second printf statament, %c must be used to display character variable.

4. In third printf statament, %f must be used to display double variable.

Ouput:

emp1 age is 20
emp1 gender is M
emp1 hourly salary is 10.000000