1. #63041
    Fluffy Kitten Dyra's Avatar
    10+ Year Old Account
    Join Date
    Oct 2009
    Location
    Fording the Ox
    Posts
    1,641
    +41

    Body feels like it was hit with hammers. Why do people insist on waking me up before I'm good and ready to be awake?

    A reader lives a thousand lives before he dies. The man who never reads lives only one.

  2. #63042
    I am Murloc! Anakso's Avatar
    10+ Year Old Account
    Join Date
    Apr 2010
    Location
    Perth, Australia
    Posts
    5,020
    Well this sucks. My Internet is down and they don't know why and the earliest they can send someone is Monday!

  3. #63043
    Deleted
    + 42

  4. #63044
    Fluffy Kitten Dyra's Avatar
    10+ Year Old Account
    Join Date
    Oct 2009
    Location
    Fording the Ox
    Posts
    1,641
    +40

    Morning spectral pandabro! <3

    A reader lives a thousand lives before he dies. The man who never reads lives only one.

  5. #63045
    Deleted
    Quote Originally Posted by Dyra View Post
    +40

    Morning spectral pandabro! <3
    Why am I spectral?
    + 41

  6. #63046
    I am Murloc! Anakso's Avatar
    10+ Year Old Account
    Join Date
    Apr 2010
    Location
    Perth, Australia
    Posts
    5,020
    Got my net working probably temporarily but it'll do for now.

    I've had a bad day! My partner that I got decided to drop out of the course so now I'm partnerless, emailed my professor asking if I can just do it alone since I've done the log and code already anyway.

    Wass help please
    One problem though my code isn't working, it compiles but this line I think is the problem, the line deciding what can't be a triangle.
    Code:
    if((side1&&side2<side3) || (side1&&side3)<side2) || (side2&&side3<side1))
    	printf("This is not a valid triangle");

    In the question it states:
    "Hint: a triangle is only valid if the sum of any given pair of sides is greater than the remaining side"

    So that was my attempt at fixing it, problem is. It gives that error message when I input any numbers except for if I input all the same numbers, then it gives me equilateral. But it won't do Isos or Scal at all. So I think there is something wrong there, like I'm saying is side2<side3 then it's invalid and it's ignoring the side 1 part so not adding them together before testing if it's smaller. I tried adding brackets around the first two so that first part would read ((side1&&side2)<side3) however when I did that, it won't even compile.
    Last edited by Anakso; 2013-03-07 at 11:03 AM.

  7. #63047
    I don't know how it works in C, but have you tried using a "+" instead of "&&"?

    as in "if((side1+side2)<side3)" ?

    Since it looks like you're comparing side1 and side2 right now, while you actually want to know the sum of the two.
    Keep in mind that I only have Java experience, so it might be different for C.

    + 42
    Last edited by Asmekiel; 2013-03-07 at 11:10 AM.

  8. #63048
    Sociology cancelled three weeks in a row. My teacher needs to get her shit together.

    + 43.

  9. #63049
    Actually, thinking about it, the 2 sides need to be larger than the first side, else you just get a line.
    Code:
    if((side1+side2)<=side3 || (side1+side3)<=side2 || (side2+side3)<=side1)
    	printf("This is not a valid triangle");
    (side1+side3)<=side2)
    also didn't work, since you were closing the if-statement too soon.

  10. #63050
    Warchief Wass's Avatar
    10+ Year Old Account
    Join Date
    Jan 2011
    Location
    PvP forums
    Posts
    2,239
    Quote Originally Posted by Asmekiel View Post
    I don't know how it works in C, but have you tried using a "+" instead of "&&"?

    as in "if((side1+side2)<side3)" ?

    Since it looks like you're comparing side1 and side2 right now, while you actually want to know the sum of the two.
    Keep in mind that I only have Java experience, so it might be different for C.

    + 42
    This was my initial thought aswell. I'm not that fluent with C/C++ however.

    Ana I'll get back to you...
    Quote Originally Posted by Dyra View Post
    Because what they are atm are plait tugging, sniffing, glaring, prissy, clothes obsessed bitches who I would quite cheerfully drown.
    I often post from my mobile device, typos in my posts are 99% likely to be because of that.
    All I would ever want and need is a hug.

  11. #63051
    Code:
    bool isTriangle(float a, float b, float c){
         
         if(a > 0 && b > 0 && c > 0){
             if( ((a + b) > c) && (abs(a - b) < c) ){
                 return true;
             }
             else{
                 return false;
             }
         }            
         else{
             return false;
         }
    }
    This was what I came up with. Hope it helps!

  12. #63052
    Warchief Wass's Avatar
    10+ Year Old Account
    Join Date
    Jan 2011
    Location
    PvP forums
    Posts
    2,239
    Quote Originally Posted by Kittypaws View Post
    Code:
    bool isTriangle(float a, float b, float c){
         
         if(a > 0 && b > 0 && c > 0){
             if( ((a + b) > c) && (abs(a - b) < c) ){
                 return true;
             }
             else{
                 return false;
             }
         }            
         else{
             return false;
         }
    }
    This was what I came up with. Hope it helps!
    Pretty much this. First if checks if all sides are positive (therefore real), the second one checks if the sum of a and b is larger than c and the absolute value of a - b is lesser than c (I hope you know what an absolute value is, the absolute value if -5 is 5, for instance). Those are the two requirements for it to be a real triangle.
    Quote Originally Posted by Dyra View Post
    Because what they are atm are plait tugging, sniffing, glaring, prissy, clothes obsessed bitches who I would quite cheerfully drown.
    I often post from my mobile device, typos in my posts are 99% likely to be because of that.
    All I would ever want and need is a hug.

  13. #63053
    Quote Originally Posted by Wass View Post
    Pretty much this. First if checks if all sides are positive (therefore real), the second one checks if the sum of a and b is larger than c and the absolute value of a - b is lesser than c (I hope you know what an absolute value is, the absolute value if -5 is 5, for instance). Those are the two requirements for it to be a real triangle.
    You will need to #include <math.h> to use abs function though.

    Also bool data type isn't available in C so you will need to use int with your function, then return 0 for false and 1 for true.

    To call the function in the main just use

    Code:
    if(isTriangle(a, b, c)){
         whatever else
    }

  14. #63054

  15. #63055
    Warchief Wass's Avatar
    10+ Year Old Account
    Join Date
    Jan 2011
    Location
    PvP forums
    Posts
    2,239
    Although I think Ana doesn't have to dismember the program into functions. He can probably just do one main() and that's it.

    like,

    cout << "Please enter the length of a: ";
    cin >> a;
    cout << "Please enter the length of b: ";
    cin >> b;
    cout << "Please enter the length of c: ";
    cin >> c;

    //if-cases go here
    Quote Originally Posted by Dyra View Post
    Because what they are atm are plait tugging, sniffing, glaring, prissy, clothes obsessed bitches who I would quite cheerfully drown.
    I often post from my mobile device, typos in my posts are 99% likely to be because of that.
    All I would ever want and need is a hug.

  16. #63056
    Quote Originally Posted by Wass View Post
    Although I think Ana doesn't have to dismember the program into functions. He can probably just do one main() and that's it.

    like,

    cout << "Please enter the length of a: ";
    cin >> a;
    cout << "Please enter the length of b: ";
    cin >> b;
    cout << "Please enter the length of c: ";
    cin >> c;

    //if-cases go here
    Yeah probably.

    Also we should really learn if he has to use C or C++, because C syntax works with C++, not the other way around.

  17. #63057
    Quote Originally Posted by Kittypaws View Post
    Yeah probably.

    Also we should really learn if he has to use C or C++, because C syntax works with C++, not the other way around.
    He said C somewhere.

    Ah, here
    Quote Originally Posted by Anakso View Post
    Will do thanks wass and long
    It is in C so that helps a heap!
    I wish my school wouldn't start with this silly C#. They do it because Visual Studio does like 90% of the work for you:/

    Oh well, back to Java.

  18. #63058
    Fluffy Kitten Dyra's Avatar
    10+ Year Old Account
    Join Date
    Oct 2009
    Location
    Fording the Ox
    Posts
    1,641
    + 42

    A reader lives a thousand lives before he dies. The man who never reads lives only one.

  19. #63059
    + 43.

    This thread makes me feel stupid.
    Nope.
    That coding stuff is stupid! Pfft!

  20. #63060
    Oh then it makes it much easier.

    Code:
    printf("Enter desired lengths of the triangle:\n");
    scanf("%d%d%d", &a, &b, &c);
    if(a > 0 && b > 0 && c > 0)
    {
            if( ((a + b) > c) && (abs(a - b) < c) )
            {
                   if(a == b && a == c)
                   {
                        printf("Triagnle is equilateral\n");
                   }
                   else if(a == b || b == c || a == c )
                   {
                        printf("Triangle is isosceles\n");
                   }
                   else 
                   {
                        printf("Triangle is sceles\n");
                   }
            }
            else 
            {
                  printf("Triangle can't be formed);
            }
    else 
    {
        printf("Triangle can't have negative sides");
    }
    }
    Should work just fine. Can make the indentation much more compact, just wanted it to be visible enough.

    Edit: might as well give the full code at this point, but I'm pretty sure you got most of it covered and will only make corrections based on this.
    Last edited by Riverness; 2013-03-07 at 11:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •