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

void main()
    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";

		  rec:cout<<"\n Enter the Length and breadth";
		      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 : ";
		      cout<<"Area of square of side "<< l <<" is "<<a;
		      goto x;

		 cir:cout<<"\n Enter the radius";
		      cout<<" Area of circle of radius "<< r <<" is "<< a;
		      goto x;

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


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 6 Years Ago by mike_2000_17: n/a

This article has been dead for over six months. Start a new discussion instead.