0

Can anybody tell me whats d problem..????

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int l,b,r,a;
    char ch,t,x;
    cout<<"******************----MAIN MENU----****************** \n";
    cout<<"\n 1.Area of rectangle";
    cout<<"\n 2.Area of square";
    cout<<"\n 3.Area of circle";

	  {
	   cout<<"\n Enter your choice";
	     cin>>ch;
	  }


		  rec:cout<<"\n Enter the Length and breadth";
		      cin>>l>>b;
		      a=l*b;
		      cout<<"\n Area of rectangle of lenght "<< l <<"  and breadth "<< b <<" is "<< a;
		      goto x;




		  sq:cout<<"\n Enter the value of sde of a square : ";
		      cin>>l;
		      a=l*l;
		      cout<<"Area of square of side "<< l <<" is "<<a;
		      goto x;




		 cir:cout<<"\n Enter the radius";
		      cin>>r;
		      a=(3.14*r*r);
		      cout<<" Area of circle of radius "<< r <<" is "<< a;
		      goto x;



	x:cout<<"\n\n  ************ Thankyou..*************";

getch();
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by mike_2000_17
0

goto is evil! You would do good to take it out of your programming vocabulary!

Now, how on earth is this code supposed to jump to rec, sq, or cir? You never test the ch that is input. Since your choices are numbers, you should input a number, not a char, but that's acceptable too. If you input a single char, you need to also call cin.ignore(); after that input because you will have dangling characters on the input stream that will make the subsequent inputs behave bizarrely.

Here, you should use a switch-case statement to determine what to do after the choice input, and forget the goto business.

Finally, you should use more obvious names for your variables. Single letter names are unreadable and have no meaning, not to mention that you might get name clashes with this kind of code (for example, you have a variable called x and a label called x, I don't know how the compiler treats it though because goto is evil and I never used it for that reason).

For the rest, it seems alright to me.

Edited by mike_2000_17: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.