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

Greetings, everyone i have trouble with this exercise in programming C. Write a

ID: 3838748 • Letter: G

Question

Greetings, everyone i have trouble with this exercise in programming C. Write a user-defined function called CalcArea that takes three decimal pointer parameters/arguments. The function prompts the user for the length and width of the object and stores those values in two of the parameters. It then calculates the area and stores that in the third parameter.

Write the function call for CalcArea. Be sure to declare ALL variables needed.

my ans was (it was wrong):(Response Feedback  

prompting should be inside the function. This does not do it the way the question asked for it Did not ask for a main function and all of that code

)

int main()

{

float Lenght = 0,

Width = 0,

areaRect =0;

  

float *Widthptr, *Lenghtptr, *areaRectptr;

Widthptr = &Width;

Lenghtptr= &Lenght;

areaRectptr = &areaRect;

printf("Please enter the lenght: ");

scanf("%f", &Lenght);

printf("Please enter the width: ");

scanf("%f", & Width);

CalcArea(Widthptr, Lenghtptr, areaRectptr);

printf(" Area of Rectangle: %f ", areaRectptr);

}

void CalcArea(float *Widthptr, float *Lenghtptr, float *areaRectptr)

{

  

*areaRectptr = *Widthptr * *Lenghtptr;

return areaRectptr;

}

Explanation / Answer

Hi

I have fixed the issue and highlighted the code changes below

#include <stdio.h>
#include <math.h>
void CalcArea(float *Widthptr, float *Lenghtptr, float *areaRectptr);
int main()
{
float Lenght = 0,
Width = 0,
areaRect =0;

CalcArea(&Width, &Lenght, &areaRect);
printf(" Area of Rectangle: %f ", areaRect);

}

void CalcArea(float *Widthptr, float *Lenghtptr, float *areaRectptr)
{
  
printf("Please enter the lenght: ");

scanf("%f", Lenghtptr);
printf("Please enter the width: ");
scanf("%f", Widthptr);

*areaRectptr = *Widthptr * *Lenghtptr;

}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Please enter the lenght: 4                                                                                                                                                                                                                                             

Please enter the width: 5                                                                                                                                                                                                                                              

                                                                                                                                                                                                                                                                       

Area of Rectangle: 20.000000