Problems in finding the area of a triangle using the heron’s Formula Using C program

Issue

This Content is from Stack Overflow. Question asked by Nxru

I am trying to do a simple c program code in which I need to find the area of a triangle using the heron’s formula with the given inputs.

The output is always 0.00 and the error trappings using do-while aren’t working as well.
I hope someone can help me.
It seems like I have a problem with the parameters or the calculations itself.
As well as the error trappings aren’t working

    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    
     void input(int *, int *, int *);
     int calculate(int, int, int, float *);
     void output(float);
     
    int main(void)
     {
        char response;
        int a, b, c;
        float area;
            do{
                input(&a, &b, &c);
                calculate(a, b, c, &area);
                output(area);
            
                printf("nn Do you want to try again?(Y/N): ");
                    scanf(" %c", &response);
                        system("cls");
            }while(response == 'Y' || response == 'y');
                return 0;
     }      
    void input(int *a, int *b, int *c)
    {
            int i;
            do{
                printf("nSide a: ");
                    scanf("%d", a);
                        if(a < 0 || a == 0)
                        {
                            i = 1;
                            printf("nThe value is incorrect, Please input a number that is greater than 0");
                        }
            }while(i == 11);
            do{
                printf("nSide b: ");
                    scanf("%d", b);
                        if(b < 0 || b == 0)
                        {
                            i = 1;
                            printf("nThe value is incorrect, Please input a number that is greater than 0");
                        }
            }while(i == 1);
            do{
                printf("nSide c: ");
                    scanf("%d", c);
                        if(c < 0 || c == 0)
                        {
                            i = 1;
                            printf("nThe value is incorrect, Please input a number that is greater than 0");
                        }
            }while( i == 1);
            return;
    }
    int calculate(int a, int b, int c, float *area)
    {
        *area = sqrt(((a+b+c)/2)*(((a+b+c)/2)-a)*(((a+b+c)/2)-b)*(((a+b+c)/2)-c));
        return;
    }
    void output(float area)
    {
        printf("nnThe area of the triangle is %.2f", area);
        return;
    }



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?