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: 3806171 • 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.

#include <stdio.h>

// employee structure definition

struct employee

{

            unsigned int age;

            char gender;

            double hourlySalary;

}

int main(void)

{

               Employee emp1; // define one struct employee variable

                                                                                                                                                                                                                                                                                                                        // Store values in the emp1

             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);

             printf(“%s%.2f ”, “emp1 hourly salary is:”, emp1.hourlySalary);

             return 0;

}

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 <stdio.h>

// employee structure definition

struct employee

{

            unsigned int age;

            char gender;

            double hourlySalary;

};

int main(void)

{

               Employee emp1; // define one struct employee variable

                                                                                                                                                                                                                                                                                                                        // Store values in the emp1

             emp1. age = 20;

              emp1. gender = X;

              emp1.hourlySalary = 10;

              printf(“%s%d ”, “emp1 age is:”, emp1.age);

              printf(“%s%c ”, “emp1 gender is:”, emp1.gender);

             printf(“%s%.2f ”, “emp1 hourly salary is:”, emp1.hourlySalary);

             return 0;

}

Explanation / Answer

1) Corrected Program 1 and output is given below

#include <stdio.h>

// employee structure definition
struct employee
{
            unsigned int age;
           char gender;
            double hourlySalary;
};

int main(void)
{
              struct employee emp1; // define one struct employee variable
           // Store values in the emp1
              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);
             printf("%s%.2f ","emp1 hourly salary is:", emp1.hourlySalary);

             return 0;

}


output                                                                                                                                                                   

emp1 age is:20                                                                                                                                                          

emp1 gender is:M                                                                                                                                                        

emp1 hourly salary is:10.00                      

2)Corrected program 2 and output is given below:

#include <stdio.h>

// employee structure definition
struct employee
{
            unsigned int age;
            char gender;
            double hourlySalary;
};

int main(void)
{
              struct employee emp1; // define one struct employee varibl
             
              // Store values in the emp1
              emp1.age = 20;
              emp1.gender = 'X';
              emp1.hourlySalary = 10;

              printf("%s%d ","emp1 age is:", emp1.age);
              printf("%s%c ","emp1 gender is:", emp1.gender);
             printf("%s%.2f ","emp1 hourly salary is:", emp1.hourlySalary);

             return 0;

}

output

emp1 age is:20                                                                                                                                                           

emp1 gender is:X                                                                                                                                                         

emp1 hourly salary is:10.00