triangle function problem

This is a discussion on triangle function problem within the C Programming forums, part of the General Programming Boards category; I'm writing my triangle problem. It's almost the end of the problem, and now I'm facing the pointer problem, so ...

  1. #1
    yusiye
    Guest

    triangle function problem

    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(input3);
      
    squareNumber(input);
      
    //midNumber(input);
      //triangleType(input, sqr);
      
    DisplayTriangleType(inputsqr);

      

    }

    int getInput(double input[])
    {
      
    int i;
      
    printf("\nInput three numbers for the triangle : ");
      for(
    0i<3i++)
         
    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 mintemp;
      
    int iswapPos;

      
    min input[0];

      for (
    0numberOfElementsi++)
      {
        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 ( 
    0i<3i++)
      {
        
    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");



  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > if((input[0]) = (input[2]))
    Try
    if((input[0]) == (input[2]))

    = is assignment
    == is comparison

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21