Oct 6, 2012 at 3:53pm Oct 6, 2012 at 3:53pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
[code][output]#include <iostream.h>
int main()
{
int a, b, c, d, q;
cout<<"what you wanna do???\n" ;
cin>>q;
if (q=='1' )
{
cout<<"first side\n" ;
cin>>a;
cout<<"second side\n" ;
cin>>b;
cout<<"third side\n" ;
cin>>c;
if ((a>b)&&(a>c))
{
d=b+c;
if (d>a)
cout<<"triangle is valid\n" ;
else
cout<<"it is not valid\n" ;
}
else if ((b>c)&&(b>a))
{
d=c+a;
if (d>b)
cout<<"triangle is valid\n" ;
else
cout<<"triangle not valid\n" ;
}
else if ((c>a)&&(c>b))
{
d=a+b;
if (d>c)
cout<<"triangle is valid\n" ;
else
cout<<"triangle not valid\n" ;
}
}
if (q=='2' )
{
cout<<"tell 1 sides\n" ;
cin>>a;
cout<<"2nd\n" ;
cin>>b;
cout<<"and 3rtd\n" ;
cin>>c;
if ((a=='b' )&&(b=='c' )&&(c=='a' ))
cout<<"equilatera; triangle\n" ;
else if ((a==b&&a!=c)||(b==c&&b!=a)||(a==c&&c!=b))
cout<<"iscosceles\n" ;
else if (a!=b!=c)
cout<<"scalene\n" ;
system("pause" );
}
return 0;
}
[/ou
tput]
[/code]
guyzz it is a program in which i have combined 2 other programs..
after the first cout , when i enter the number of the conditional operator , it is closing down.. automatically.. i mean the application window.
the 2 programs are
wheither a triangle is valid [for 1]
2 tell the triangle type[for 2]
tell me what i have done wrong!!
Last edited on Oct 6, 2012 at 3:53pm Oct 6, 2012 at 3:53pm UTC
Oct 6, 2012 at 4:19pm Oct 6, 2012 at 4:19pm UTC
You have
if (q=='1' )
which should be if (q == 1)
What you are doing is comparing q to the char 1, not the number 1, which you should be doing.
Same with
if (q=='2' )
Oct 6, 2012 at 4:52pm Oct 6, 2012 at 4:52pm UTC
thank you that really helped me!!