在我的代码中查找错误(C ++) [英] Find error in my code (C++)
本文介绍了在我的代码中查找错误(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();
}
我的尝试:
i尝试运行此代码..有些问题请帮助
What I have tried:
i tried to run this code..some problem there please help
推荐答案
没有类型long float
在C / C ++中。有float
,double
和long double
。请注意,long double
与double
相同,其中包含一些编译器和库,如Visual C ++。
There is no typelong float
in C/C++. There arefloat
,double
, andlong double
. Note thatlong double
is the same asdouble
with some compilers and libraries like with Visual C++.
你声明了int ch;但在切换案例中,您正在比较选项char。将案例更改为
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;
}
这篇关于在我的代码中查找错误(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文