I'm writing my triangle problem. It's almost the end of the problem, and now I'm facing the pointer problem, so how to fix it. [font color = red]IT's in the last part[/font]
Here's the code:
PHP Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void doTriangle(); //Main routine
void tError(double input[]); //Print any error messages
double squareNumber(double input[]); //Square the number
int getInput(double input[]); //Get three items and return them in and array
int triangleType(double input[], double sqr[]); //Find what type of triangle it is
void DisplayTriangleType(double input[], double sqr[]); //Display the triangle type
void selectionSort(double triangle[], int numberOfElements); //Sort list
int maxNumber(double input[]); //Largest Number in List
int minNumber(double input[]); //Smallest Number in List
int midNumber(double input[]); //Middle number in the list
int main()
{
doTriangle();
return 0;
}
void doTriangle()
{
double input[3];
double sqr[3];
getInput(input);
selectionSort(input, 3);
squareNumber(input);
//midNumber(input);
//triangleType(input, sqr);
DisplayTriangleType(input, sqr);
}
int getInput(double input[])
{
int i;
printf("\nInput three numbers for the triangle : ");
for(i = 0; i<3; i++)
scanf("%lf", &input[i]);
tError(input);
return 0;
}
void tError(double input[])
{
while (input[0] <= 0){
printf("Input value can't be negtive or zero!");
getInput(input);
break;}
while ((input[0]) + (input[1]) <= (input[2])){
//if ((maxNumber) >= (minNumber + midNumber))
printf("The input value is illegal!");
getInput(input);
break;}
//selectionSort(input, 3);
}
void selectionSort(double input[], int numberOfElements)
{
double min, temp;
int i, swapPos;
min = input[0];
for (i = 0; i < numberOfElements; i++)
{
if (min > input[i])
{
min = input[i];
swapPos = i;
}
}
if (numberOfElements != 1)
{
temp = input[0];
input[0] = min;
input[swapPos] = temp;
printf("%.2lf ", input[0]);
selectionSort(&input[1], numberOfElements - 1);
}
else
printf("%.2lf ", input[0]);
}
int maxNumber(double input[])
{
double *maxNumber;
maxNumber = &input[2];
printf("\n%.2lf", *maxNumber);
return *maxNumber;
}
int minNumber(double input[])
{
double *minNumber;
minNumber = &input[0];
printf("\n%.2lf", *minNumber);
return *minNumber;
}
int midNumber(double input[])
{
double *midNumber;
midNumber = &input[1];
printf("\n%.2lf", *midNumber);
return *midNumber;
}
/*int squareNumber(double a, double b, double c)
{
double sqr[3];
sqr[0] = a*a;
sqr[1] = b*b;
sqr[2] = c*c;
printf("%.2lf %.2lf %.2lf", sqr[0], sqr[1], sqr[2]);
return 0;
}*/
double squareNumber(double input[])
{
int i;
double sqr[3];
for ( i = 0; i<3; i++)
{
sqr[i] = input[i] * input[i];
}
printf("%.2lf %.2lf %.2lf", sqr[0], sqr[1], sqr[2]);
return 0;
}
//COMMENT: I can't fix this part!!! I want know what'wrong with this function?//
void DisplayTriangleType(double input[], double sqr[])
{
if((input[0]) = (input[2]))
printf("It is Equilateral");
else
if((input[0]) = (input[1]))
printf("It is Isosceles");
else
if((sqr[0]) + (sqr[1]) = (sqr[2]))
printf("It is Right");
else
if((sqr[0]) + (sqr[1]) > (sqr[2]))
printf("It is Acute");
else
if((sqr[0]) + (sqr[1]) < (sqr[2]))
printf("It is Obtuse");
}