+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?
+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.
Well this sucks. My Internet is down and they don't know why and the earliest they can send someone is Monday!
+ 42
+40
Morning spectral pandabro! <3
A reader lives a thousand lives before he dies. The man who never reads lives only one.
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.
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.
Sociology cancelled three weeks in a row. My teacher needs to get her shit together.
+ 43.
Actually, thinking about it, the 2 sides need to be larger than the first side, else you just get a line.
(side1+side3)<=side2)Code:if((side1+side2)<=side3 || (side1+side3)<=side2 || (side2+side3)<=side1) printf("This is not a valid triangle");
also didn't work, since you were closing the if-statement too soon.
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 }
+ 44
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
+ 42
A reader lives a thousand lives before he dies. The man who never reads lives only one.
+ 43.
This thread makes me feel stupid.
Nope.
That coding stuff is stupid! Pfft!
Oh then it makes it much easier.
Should work just fine. Can make the indentation much more compact, just wanted it to be visible enough.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"); } }
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.