Puhleeeease check this .......
Isnt giving the correct output ...  int a,b,c;


printf("Enter the sides...");

scanf("%d %d %d",&a,&b,&c);


if (a<(b+c))

printf("The triangle is valid.");

else if (b<(c+a))

printf("The triangle is valid.");

else if (c<(a+b))

printf("The triangle is valid.");

else

printf("The triangle is invalid.");


14 16240
Nested if statements are an OR condition.
If your triangle is a= 10, b= 4 and c = 5:
then a < (b+c) is false. This is an invalid triangle. However the else goes onto to check b < (c+a) which is true. And so your program displays that the triangle is valid.
Once you have detected an invalid triangle, your program should stop and not continue on.
There are various ways to code this and I leave that up to you.
Puhleeeease check this
For what? Don't give us a code dump and set us off with "find the errors". We can do bug hunting on our own code, thanks. Ask a real question.
Isnt giving the correct output ...
So maybe you should program it to give the correct output. If you don't give us anymore details than "it is not correct", than we won't give you a response any better than "make it correct".
Details please. What do you observe? What did you try? Where did you narrow the problem down to? Don't dump work on us with little information.
EDIT: As a hint, try to use braces more explicitly. It makes it clear what the blocks of code are. This is especially true in if/else one liners, which when nested without the braces can become confusing to read. You don't know what else matches to what if.
Banfa 9,065
Expert Mod 8TB
You may also wish to tell us, in English/Maths, the algorithm you think you are solving. I can pretty much guarantee that all the experts/mods that have posted so far know the algorithm for detecting a valid triangle but from what you have posted it is not clear if you  Know the algorithm to detect a valid triangle but have implemented it incorrectly
 Do not know the algorithm to detect a valid triangle but have implemented the algorithm you think it should be correctly
 Do not know the algorithm to detect a valid triangle but have implemented the algorithm you think it should be but implemented that incorrectly
And before you laugh I have seen c happen in commercial projects all be it on a slightly more complex algorithm.
Sorry.
I have to input three sides of a triangle and check them to decide if the triangle is valid or not.
The result has to be displayed .
Another version I had tried is below, but the control never enters the "invalid" part, i always get the "Triangle is valid" message.
I think the problem is with the hierarchy structure for OR ... 


#include <stdio.h>

#include <conio.h>

#include <math.h>


main()


{ int a,b,c;


printf("Enter the sides...");

scanf("%d %d %d",&a,&b,&c);


if ((a<(b+c))(b<(c+a))(c<(a+b)))

printf("The triangle is valid.");

else

printf("The triangle is invalid.");


getch();

return 0;

}
Any further suggetions???
Banfa 9,065
Expert Mod 8TB
I have to input three sides of a triangle and check them to decide if the triangle is valid or not.
As I already tried to say (but was may be unclear) what algorithm are you using to determine if the 3 sides do or don't form a valid triangle.
Banfa 9,065
Expert Mod 8TB
Bookmark the Wolfram Mathworld site; it's valuable.
Thank you I have, unfortunately it now appears that I have to spend about 6 months browsing this site so you all on your own for a while :D
The condition is to check
((a<(b+c))(b<(c+a))(c<(a+b)))
that is....
sum of any 2 sides is greater than the third side
Will i have to check for the smallest side first and then proceed ?
Banfa 9,065
Expert Mod 8TB
This
((a<(b+c))(b<(c+a))(c<(a+b)))
and this
sum of any 2 sides is greater than the third side
are not the same thing, the second one is correct, the first one is not a correct implementation of it.
In order for it to be a triangle, the sum of any two sides must be greater than the third side. In other words, side1 + side2 > side3 for ALL side1, side2, or side3. Does that sound like a condition requiring AND, or a condition requiring OR? You've programmed it with OR (), and you are getting wrong results  what does that tell you?
Thanks a million,don't know how I never missed it !
Maybe coz i got the algorithm corrected from my prof, but we both didn't notice the error....
Thanks ever so much!
Thank you I have, unfortunately it now appears that I have to spend about 6 months browsing this site so you all on your own for a while :D
It's an extremely nice site with quite a history: first Eric Weisstein (sp?) built
that side by himself, he agreed to have a book published (a snapshot of the site)
but later the book publisher forbid him to work on his own site; it was his 'grand
opus' and was stuck because of lawsuits etc. Then Wolfram came in and 'bought'
the entire site including all book rights etc. and now everything is up and running
again.
kind regards,
Jos
please use this condion for if " if (((a+b)<c)((b+c)<a)((a+c)<b))"
all the inequalities need to be true so && operator should be used instead of 
since a+b>c &&
a+c>b &&
b+c>a &&
should be put in if as a condition
if it is true
den valid triangle
else
invalid triangle
Sign in to post your reply or Sign up for a free account.
Similar topics
by: coinjo 
last post by:
I need to write a program, which takes two inputs:
â€¢ï€ ï€ a value n that represents the number of elementsin the
longest row of a triangle.
â€¢ï€ ï€ a character c to be printed in place of each...

by: VISHNU VARDHAN REDDY UNDYALA 
last post by:
Hi,
Could anyone over here, write a program in C using only for loop to
print the following output
*
***
*****
*******
*********
***********

by: javadkhan 
last post by:
Hi All,
I am trying to supress the small black triangle that shows up in the
menus meaning the menuitem is parent. The reason for that is I drew my
own 3D looking triangle in DrawItem using...

by: Leo 
last post by:
Can someone tell me how to make the sorting triangle on
datagrid column header always show up?
And which property can change the color of the triangle ?
The default color is white.
Thanks

by: singhm 
last post by:
Hi guys so I have a trianlge program having hard time finishing this though,
I have to develop a program which is the following:
Write a program that will allow the user to enter the 3 lengths...

by: Andy Dingley 
last post by:
Here's a chunk of a longer piece of punditry I'm working on, re: the
choices between doctypes for authoring and the State of the Union for
validity. I've got a bucketload of nasty code and a bunch...

by: geo039 
last post by:
I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 constructors...

by: lost1 
last post by:
Can someone point me in the right direction on how to get the triangle type to display. Below is a triangle class that is tested by another completely separate class. The main method of the test...

by: jackj 
last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a...

by: CloudSolutions 
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

by: Faith0G 
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

by: isladogs 
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...

by: Charles Arthur 
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone

by: aa123db 
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...

by: ryjfgjl 
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and timeconsuming...

by: ryjfgjl 
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...

by: nemocccc 
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

by: Sonnysonu 
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by columnwise with in the specific length.
suppose the i have to...
 