English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

//in c programming
main()
{
int a,b,c;int flag=0;
printf("enter the sides of triangle");
scanf("%d%d%d",&a,&b,&c);
while(flag==0)
{
if(a==b&b==c)
{
printf("triangle is equilateral");
break;
}
if(a==b||b==c||c==a)
{
printf(triangle is isoceles");
break;
}
if(a!=b&&b!=c&&c!=a)
{
printf("triangle is scalene");
break;
}
}//while closes
getch();
}
but compiler shows error in break says misplaced break

2007-08-14 06:40:55 · 5 answers · asked by nikhil k 1 in Computers & Internet Programming & Design

5 answers

You're missing a quote on "triangle is isoceles."

Other than that, it compiles for me.

2007-08-14 06:48:43 · answer #1 · answered by McFate 7 · 1 0

I compiled this with Visual Studio and found two errors:

You are missing a quote (") on the line that says

printf(triangle is isoceles")

and I noticed one logical error on this line:

if(a==b&b==c)

it should read:

if ( a==b && b==c )

the single & means bitwise and but you want a logical and which is two & (&&).

However, I did not get an error saying misplaced break. When I corrected those two errors, the program compiled and ran perfectly.

2007-08-14 13:58:38 · answer #2 · answered by TreyJ 3 · 1 0

The most common error when there is a misplaced break is not a misplaced break.. Look at your parenthesis and make sure you have enough. Usually you are missing one parenthesis at the end and it will screw all of the code. Also I am not sure if you can use multiple breaks like that. Especially when you dont specifiy where to break to. Sometimes a break can even end all the code and break the program so maybe you could use something else instead of a break. Such as a call function.

2007-08-14 13:57:24 · answer #3 · answered by Ashton 2 · 0 0

main()
{
int a,b,c;int flag=0;
printf("enter the sides of triangle");
scanf("%d%d%d",&a,&b,&c);
while(flag==0)
{
if(a==b&b==c)
{
printf("triangle is equilateral");
flag=1;
break;
}
if(a==b||b==c||c==a)
{
printf(triangle is isoceles");
flag=1;
break;
}
if(a!=b&&b!=c&&c!=a)
{
printf("triangle is scalene");
flag=1;
break;
}
}//while closes
getch();
}

2007-08-14 13:50:17 · answer #4 · answered by Honest_&_Loyal 3 · 0 1

the break statement breaks the all loops so don,t use more than one break statements in the loop

2007-08-14 13:48:20 · answer #5 · answered by satya e 2 · 0 2

fedest.com, questions and answers