Thread: Who can check my code?

  1. #1
    Registered User
    Join Date
    Apr 2021

    Who can check my code?

    //My program working but i don't know, i did it in correct way or not.?
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    struct triagle
        float point1;
        float point2;
        float point3;
    float tr_perimetr(float x,float y,float z)
        float perimetr;
        perimetr = x+y+z;
        return perimetr;
    int main()
        struct triagle perimetr;
        int num;
        perimetr.point1 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
        perimetr.point2 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
        perimetr.point3 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
        printf("Perimetr of triangle with edges of %.1f\t%.1f and %.1f = %.1f",perimetr.point1,perimetr.point2,perimetr.point3,tr_perimetr(perimetr.point1,perimetr.point2,perimetr.point3));
        return 0;
    Attached Images Attached Images Who can check my code?-xaldu-jpg 

  2. #2
    Registered User
    Join Date
    Dec 2017
    Well, "triangle" has an 'n' in it.
    And you aren't storing "points" but side lengths.
    Also, the exercise says to pass a triangle to the function, not it's separate side lengths.
    The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts. - Bertrand Russell

  3. #3
    Registered User
    Join Date
    May 2009
    An point is normally considered two values often called x and y values.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Feb 2019
    john.c and stahta01 have a point (sorry didn't resist the pun).

    You are dealing with triangle SIDES, not vertices. And choosing 3 random values between -10 and 10:

     rand()/(float)RAND_MAX -> Will be a value between 0 and 1.
    (rand() / (float)RAND_MAX) * 20 -> Will be a value between 0 and 20.
    (rand() / (float)RAND_MAX) * 20 - 10 -> Will be a value between -10 and 10
    Not all choosen values are valid as "lengths"...
    Last edited by flp1969; 06-25-2021 at 07:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. check my code
    By senkuu in forum C Programming
    Replies: 1
    Last Post: 09-14-2016, 09:02 AM
  2. Help! Check my code over.
    By omGeeK in forum C Programming
    Replies: 6
    Last Post: 11-04-2010, 11:34 PM
  3. check my c code.
    By rfm in forum C Programming
    Replies: 4
    Last Post: 09-24-2009, 05:47 AM
  4. Check out my code
    By joshdick in forum C++ Programming
    Replies: 9
    Last Post: 09-17-2003, 07:41 PM
  5. check the code
    By pasha in forum Windows Programming
    Replies: 2
    Last Post: 01-06-2003, 02:01 PM

Tags for this Thread