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

Execute the following code and identify the errors in the program. Debug the pro

ID: 3806177 • Letter: E

Question

Execute the following code and identify the errors in the program. Debug the program and provide the correct version of the code.

#include <stdio.h>

// employee structure definition

struct employee

{

            unsigned int age;

            char gender;

            double hourlySalary;

            struct employee e1;

};

int main(void)

{

                           // Store values in the e1

             e1. age = 18;

              e1. gender = ‘F’;

              e1.hourlySalary = 11.50;

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

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

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

             return 0;

Execute the following code and identify the errors in the program. Debug the program and provide the correct version of the code.

int main (void)

{

               struct employee emp1; // define one struct employee variable

               struct employee emp2;

              // place strings into emp1

             emp1.age = 20

             emp1.hourlySalary = 25;

             //emp2

            emp2.age = 25

            emp2.hourlySalary = 25;

           if (emp1 > emp2)

           {

                        printf(“ emp1 salary is greater than emp2 ”)

           }

           return 0;

}

Execute the following code and identify the errors in the program. Debug the program and provide the correct version of the code. Note: Be sure to check the output screen to see if the correct values are displaying according.

#include <stdio.h>

// employee structure definition

struct employee

{

             unsigned int age;

             double hourlySalary;

};

#include <stdio.h>

// number union definition

union number

{

               int x;

               double y;

};

int main (void)

{

               union number value;

              

               value.x = 100;

               printf(“x is %d ”, value.x);

               printf(“y is %.2f ”, value.y);

              return 0;

}

Execute the following code and identify the errors in the program. Debug the program and provide the correct version of the code. Be sure the output looks exactly like the screen shot below.

#include <stdio.h>

// days enumeration

enum days

{

              MON = 0, TUE, WED, THU, FRI, SAT, SUN

}

int main(void)

{

            Const char *dayName[] = { “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday” };

            for (enum days day = MON; day <= SUN; day++)

            {

                        printf(“%2d%11s ”, day, dayName[day]);

            }

       

            return 0;

}

Execute the following code and identify the errors in the program. Debug the program and provide the correct version of the code.

#include <stdio.h>

// days enumeration

enum days

{

              MON = 1, TUE, WED, THU, FRI, SAT, SUN

};

int main(void)

{

            Const char *dayName[] = { “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday” };

            for (enum days day = MON; day <= SUN; day++)

            {

                        printf(“%2d%11s ”, day, dayName[day]);

            }

       

            return 0;

}

Explanation / Answer

Corrected programs and output is given below:

1)

#include <stdio.h>

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

int main(void)
{
            // Store values in the e1
              e1.age = 18;
              e1.gender = 'F';
              e1.hourlySalary = 11.50;

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

             return 0;
}

output

e1 age is:18                                                                                                                                                             

e1 gender is:F                                                                                                                                                           

e1 hourly salary is:11.50

2)

#include <stdio.h>

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

int main (void)
{
               struct employee emp1; // define one struct employee variable
               struct employee emp2;

              // place strings into emp1
             emp1.age = 20;
             emp1.hourlySalary = 25;

             //emp2
            emp2.age = 25;
            emp2.hourlySalary = 25;

           if (emp1.hourlySalary > emp2.hourlySalary)
           {
                        printf(" emp1 salary is greater than emp2 ");
           }

           return 0;

}

//as emp1 and emp2 salary is equal i.e. 25 therefore output is nothing.

3)

#include <stdio.h>

// number union definition
union number
{
               int x;
               double y;
};

int main (void)
{
               union number value;

               value.x = 100;

               printf("x is %d ",value.x);

               printf("y is %.2f ",value.y);

              return 0;

}

output

x is 100                                                                                                                                                                 

y is 0.00

4)

#include <stdio.h>

// days enumeration
enum days
{

              MON = 0, TUE, WED, THU, FRI, SAT, SUN,

};

int main(void)
{
    enum days day;
    const char *dayName[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

            for(day=MON;day<=SUN;day++)
            {

                        printf("%2d%11s ",day,dayName[day]);

            }

     
            return 0;

}

output

0     Monday                                                                                                                                                            

1    Tuesday                                                                                                                                                            

2  Wednesday                                                                                                                                                            

3   Thursday                                                                                                                                                            

4     Friday                                                                                                                                                            

5   Saturday                                                                                                                                                            

6     Sunday  

5)

#include <stdio.h>

// days enumeration
enum days
{
              MON = 1,TUE,WED,THU,FRI,SAT,SUN
};

int main(void)
{
    enum days day;
    const char *dayName[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
            for (day=MON;day<=SUN;day++)
            {
                        printf("%2d%11s ",day,dayName[day]);
            }

            return 0;

}

output

1    Tuesday                                                                                                                                                            

2  Wednesday                                                                                                                                                            

3   Thursday                                                                                                                                                            

4     Friday                                                                                                                                                            

5   Saturday                                                                                                                                                            

6     Sunday