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

This exercise problem, I having problems to find the solutions for error that oc

ID: 3797152 • Letter: T

Question

This exercise problem, I having problems to find the solutions for error that occurs in practice problems and needs help solve these problems?

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

Question1:-

#include<stdio.h>
// employee structure definition
struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} //Error1

int main(void)
{
employee emp1; // define one struct employee variable //Error2
emp1.age=20; // store values in the emp1
emp1.gender='M'; // store values in the emp1
emp1.hourlySalary=10; // store values in the emp1
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;
}

The correct version of the code:-

#include<stdio.h>
struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} emp1;

int main(void)
{

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

Explanation:-

Error1:-

You should place the semicolon ; in the ending line.

Error2:-

We should follow either of the two ways to create Structure variables.

1.struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} emp1;

2.struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} ;

struct employee emp1;

Question3:-

#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 //Error1
emp1.age=20; // store values in the emp1
emp1.gender=X; // store values in the emp1 //Error2
emp1.hourlySalary=10; // store values in the emp1
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;
}

The correct version of the code:-

#include<stdio.h>
struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} emp1;

int main(void)
{

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

Error1:-

We should follow either of the two ways to create Structure variables.

1.struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} emp1;

2.struct employee
{
unsigned int age;
char gender;
double hourlySalary;
} ;

struct employee emp1;

Error2:-

We should place the character data or information in the quotes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote