Click here to Skip to main content
15,513,142 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
//RECTANGLE
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
main()
{
clrscr();
int ch;
char ch1;
long float l,b,area,peri,diag;
cout<<"Rectangle Menu: \n";
cout<<"1.Area\n";
cout<<"2.Perimeter\n";
cout<<"3.Diagonal\n";
cout<<"4.Exit\n";
cout<<"Enter your choice(1-4): ";
do
	{
	cin>>ch;
	if(ch==1 || ch==2 || ch==3)
	{	cout<<"Enter Length and Breadth :\n";
		cin>>l>>b;
	}
	switch(ch)
	{
	case'1':
		area=l*b;
		cout<<"Area= "<<area;
		break;
	case'2':
		peri=2*(l+b);
		cout<<"Perimeter= "<<peri;
		break;
	case'3':
		diag=sqrt((l*l)+(b*b));
		cout<<"Diagonal= "<<diag;
		break;
	case'4':
		cout<<"Exiting....";
		exit(0);
	default:
		cout<<"Wrong choice!!!!";
		cout<<"Enter a valid choice";
		break;
	}
	cout<<"\nWant to enter more(y/n)? ";cin>>ch1;
	if(ch1=='y' || ch1=='Y')
		cout<<"Again enter choice(1-4): ";
	}
	while(ch1=='y' || ch1=='Y');
getch();
}


What I have tried:

i tried to run this code..some problem there please help
Posted
Updated 13-Jul-18 3:38am
v2
Comments
[no name] 13-Jul-18 12:50pm    
"some problem there please" is not helpfull. Can you specify the Problems you are facing?

There is no type long float in C/C++. There are float, double, and long double. Note that long double is the same as double with some compilers and libraries like with Visual C++.
 
Share this answer
 
Comments
Manish K. Agarwal 13-Jul-18 8:43am    
at least VS2010, compile 'long float' with a size of 8 bytes while only 'long' or 'float' have 4 bytes
Jochen Arndt 13-Jul-18 9:10am    
Have not tried it with VC, it is not standard, and even not mentioned in the MS documentation at Fundamental Types (C++).

Tried it with older GCC and G++ versions: Both throw an error.
You declared int ch; but in switch case you are comparing options char. change case as

switch(ch)
 {
 case 1:
 area=l*b;
 cout<<"Area= "<<area;
 break;
 case 2:
 peri=2*(l+b);
 cout<<"Perimeter= "<<peri;
 break;
 case 3:
 diag=sqrt((l*l)+(b*b));
 cout<<"Diagonal= "<<diag;
 break;
 case 4:
 cout<<"Exiting....";
 exit(0);
 default:
 cout<<"Wrong choice!!!!";
 cout<<"Enter a valid choice";
 break;
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900