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

need help with correct c program code.my code is listed after the example and in

ID: 3787589 • Letter: N

Question

need help with correct c program code.my code is listed after the example and instructions. and my errors, but Im not sure if my is correct becuase i dont think i can use strycpy. please check and help.

- In the program I need to make a input three real (floating point) numbers from the keyboard and calculate a number of properties about the numbers.

-3 values would read a single scanf() statement.

-Then call each of five functions you will write.

-Each function will pass the three values that are input the function will perform the requested calculation.then return the required result.

- functions to be written are----

- Determine which of 3 #'s is largest and return that value.

-Determine which of 3#'s values is the smallest and return that value.

-Determine if all 3 #'s are equal to each other.

Return the character ‘=’ if they are, or the character ‘#’ if two or more have different values.

Calculate and return the average of the 3 values

An example is attached when run.

MY CODE

using stdafx.h

#define EPSILON 0.1
float maxval(float v1, float v2, float v3)
{
   if (v1 > v2 && v1 > v3)
       return v1;
   else if (v2 > v1 && v2 > v3)
       return v2;
   else
       return v3;
}

float minval(float v1, float v2, float v3)
{
   if (v1 < v2 && v2 < v3)
       return v1;
   else if (v2 < v1 && v2 < v3)
       return v2;
   else
       return v3;
}
char equalval(float v1, float v2, float v3)
{
   if (v1 == v2 && v2 == v3 && v2 == v3)
       return '=';
   else
       return '#';
}
float averageval(float v1, float v2, float v3)
{
   return (v1 + v2 + v3) / 3;
}
char nearequal(float v1, float v2)
{
   if ((v2 - v1) < EPSILON)
       return 'Y';
   else
       return 'N';
}

int main()
{
   float v1, v2, v3;
   printf("Enter three real numbers:");
   scanf_s("%f %f %f", &v1, &v2, &v3);

   float max = maxval(v1, v2, v3);
   float min = minval(v1, v2, v3);
   float avg = averageval(v1, v2, v3);
   char eql = equalval(v1, v2, v3);
   char equal[10];
   if (eql == '=')
       strcpy(equal, "Yes");
   else
       strcpy(equal, "No");
   char neql = nearequal(v1, v2);
   char nequal[10];
   if (neql == 'Y')
       strypy(nequal, "No");

   printf("------------------------ ");
   printf("Val1 Val2 Val3 Max Min Avg All-Equal Near-Equal Epsilon ");
   printf("------------------------ ");
   printf("%0.2f %0.2ft %0.2f %0.2f %0.2ft %s %s %0.2f ", v1, v2, v3, max, min, avg, equal, nequal, EPSILON);
   printf("------------------------- ");

return 0;
}

This program will calculate several properties with respect to three floating point values entered. Enter three real numbers 6.05 6.1 7.5 val 1 val 2 val 3 Max Min Avg All-Equal Near-Equal Epsilon I I 6.05 6.10 7.50 7.50 6.05 6.55 No Yes

Explanation / Answer

Please find below a perfectly fine running program based on the code you have provided. I have compiled it using the DEV C Compiler. All minor errors have been removed and the code is working as it should be.

#include <stdio.h>
#include <string.h>
#include <conio.h>
#define EPSILON 0.1
float maxval(float v1, float v2, float v3)
{
if (v1 > v2 && v1 > v3)
return v1;
else if (v2 > v1 && v2 > v3)
return v2;
else
return v3;
}
float minval(float v1, float v2, float v3)
{
if (v1 < v2 && v2 < v3)
return v1;
else if (v2 < v1 && v2 < v3)
return v2;
else
return v3;
}
char equalval(float v1, float v2, float v3)
{
if (v1 == v2 && v2 == v3 && v2 == v3)
return '=';
else
return '#';
}
float averageval(float v1, float v2, float v3)
{
return (v1 + v2 + v3) / 3;
}
char nearequal(float v1, float v2)
{
if ((v2 - v1) < EPSILON)
return 'Y';
else
return 'N';
}
int main()
{
float v1, v2, v3;
printf("Enter three real numbers:");
scanf("%f %f %f", &v1, &v2, &v3);
float max = maxval(v1, v2, v3);
float min = minval(v1, v2, v3);
float avg = averageval(v1, v2, v3);
char eql = equalval(v1, v2, v3);
char equal[10];
if (eql == '=')
strcpy(equal, "Yes");
else
strcpy(equal, "No");
char neql = nearequal(v1, v2);
char nequal[10];
if (neql == 'Y')
strcpy(nequal, "Yes");
else
   strcpy(nequal, "No");
  
printf("-------------------------------------------------------------------------- ");
printf("Val1 Val2 Val3 Max Min Avg All-Equal Near-Equal Epsilon ");
printf("-------------------------------------------------------------------------- ");
printf("%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f %s %s %0.1f ", v1, v2, v3, max, min, avg, equal, nequal,EPSILON);
printf("-------------------------------------------------------------------------- ");
return 0;
}