The question states: The formula for the area of any triangle is:
A = √(s(s-a)(s-b)(s-c)) where s= (a+b+c)/2
Write a program that will allow the user to make at least one area calculation, your program will prompt the user if he wishes to continue and it will stop once the user enters the character N or n. Assume that the length units are cm. Your solution must include a user-define function that returns the area of the triangle and its inputs are the three sides.
float areaTriangle(float sideA, float sideB, float sideC);
The following is the code I have at the moment but can't finish because of the errors.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float areaTriangle(float sideA, float sideB, float sideC);
int main() {
float sideA, sideB, sideC;
char answer;
printf("Please enter the length of side A: \n");
scanf("%f", &sideA);
printf("Please enter the length of side B: \n");
scanf("%f", &sideB);
printf("Please enter the length of side C: \n");
scanf("%f", &sideC);
do {
printf("Would you like to solve another\n"
"exercise?\n"
" Y or N ");
scanf(" %c", &answer);
printf("The area of the triangle is: %f", &areaTriangle(sideA, sideB, sideC));
} while (char == 'Y');
do {
printf("Would you like to solve another\n"
"exercise?\n"
" Y or N ");
scanf(" %c", &answer);
printf("You have selected to quit out of the program.\n"
"Thank you for using the program.\n");
} while (char == 'N');
return 0;
}
float areaTriangle(float sideA, float sideB, float sideC) {
float sideVariable;
sideVariable = (sideA + sideB + sideC) / 2;
areaTriangle = sqrt(sideVariable * (sideVariable - sideA) *
(sideVariable - sideB) * (sideVariable - sideC));
return areaTriangle;
}
I believe I messed up in my function definition and the function call. Also, I am not sure whether I should have all the variables that I included.
The list of errors I am getting:
45:error: lvalue required as unary '&' operand
46 and 51:expected expression before 'char'
60:note declared here
64:error: lvalue required as left operand of assignment
68:error: expected expression before 'float'
69:warning: control reaches end of non-void function