So I'm writing a program in C, and am trying to figure something out. This particular assignment was easy until I got to part 5. The instructions are as follows:
Part 5 - Write a main function that uses get_value() in order to querythe user for the width and height of a right triangle. Then, if the width andheight are valid values, the program displays 3 choices:1. Calculate length of hypothesis.2. Calculate area of the triangle.3. Calculate the perimeter of the triangle.Then, based on the choice entered by the user (1-3) the program calls theappropriate function and displays the results. If the inputs are not correctthen an error message is displayed.
These instructions are supposed to be applied to the code I've already written so far, which is
Code:
#include <stdio.h>
#include <math.h>
double get_value();
double calc_hypotenuse(double h, double w);
double calc_area(double h4, double w4);
double calc_perimeter(double h3, double w3, double hypotenuse);
int main()
{
double hh, ww;
double hhh, www;
double hhhh, wwww;
double hhhhh, wwwww;
printf("%.2lf\n\n", get_value());
printf("Enter a height and width for a right triangle to calculate the length of the hypotenuse.\n");
printf("Height: ");
scanf("%lf", &hh);
printf("Width: ");
scanf("%lf", &ww);
printf("The length of the hypotenuse is %.2lf.\n\n", calc_hypotenuse(hh, ww));
printf("Enter a height and width for a right triangle to calculate the area.\n");
printf("Height: ");
scanf("%lf", &hhhh);
printf("Width: ");
scanf("%lf", &wwww);
printf("The area is %.2lf.\n\n", calc_area(hhhh, wwww));
printf("Now enter a height and width for a right triangle to calculate the perimeter.\n");
printf("Height: ");
scanf("%lf", &hhh);
printf("Width: ");
scanf("%lf", &www);
printf("The perimeter is %.2lf.\n\n", calc_perimeter(hhh, www, calc_hypotenuse(hhh, www)));
return 0;
}
double get_value()
{
double value;
printf("Enter a value of type double between 0.0 and 10,000.0: ");
scanf("%lf", &value);
if ((value > 0) && (value < 10000))
return value;
else
return -1;
}
double calc_hypotenuse(double h, double w)
{
return sqrt(pow(h, 2) + pow(w, 2));
}
double calc_area(double h4, double w4)
{
return .5*(h4 * w4);
}
double calc_perimeter(double h3, double w3, double hypotenuse)
{
return h3 + w3 + hypotenuse;
}
I just don't quite understand how I'm supposed to get the get_value( ) function to essentially perform differently the second time I call on it. Any help is MUCH appreciated. Thanks guys. By the way, I'd appreciate it if you could explain instead of just posting some code.