新手求助:VC程序

lanbingerfly 2011-03-07 12:25:10
#include<iostream.h>
#include<conio.h>
#include<math.h>
float area(float x,float y,float z);
int main()
{ float a,b,c,s;
cout<<"please input 3 sides of one triangle:"<<endl;
cin>>a>>b>>c>>endl;
cout<<a<<b<<c<<endl;
s=area(a,b,c);
cout<<"area of triangle is:"<<endl;
}
float area(float x,float y,float z)
{
float p,t;
p=(x+y+z)/2;
t=sqrt(p*(p-x)(p-y)(p-z));
return t;
}
这是一个求三角形面积的VC程序,编译时老出错,错误如下:Compiling...
liu.cpp
c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(11) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class ostream &(__cdecl *)(class ostream &)' (or there is no acceptable conversion)
c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(24) : error C2064: term does not evaluate to a function
执行 cl.exe 时出错.

liu.obj - 1 error(s), 0 warning(s)
请问是什么原因?
...全文
116 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanbingerfly 2011-03-08
  • 打赏
  • 举报
回复
嗯,这次好了,谢了
Dreadnought 2011-03-07
  • 打赏
  • 举报
回复
c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(11) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class ostream &(__cdecl *)(class ostream &)' (or there is no acceptable conversion) 你加入using namespace std; 或者std::cout std::com std::endl试试

c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed main函数应该返回个值,


c:\program files\microsoft visual studio\myprojects\liu\liu.cpp(24) : error C2064: term does not evaluate to a function 解决 error C2064 这种错误,关键是找到它所指向的错误行里面所有调用的函数名,他们中一定至少有一个是未被定义过的。
TandyT 2011-03-07
  • 打赏
  • 举报
回复
完整的为:


#include<iostream.h>
#include<conio.h>
#include<math.h>
float area(float x,float y,float z);
int main()
{ float a,b,c,s;
cout<<"please input 3 sides of one triangle:"<<endl;
cin>>a;
cin>>b;
cin>>c;
cout<<endl;
cout<<a<<b<<c<<endl;
s=area(a,b,c);
cout<<"area of triangle is:"<<endl;
return 0;
}
float area(float x,float y,float z)
{
float p,t;
p=(x+y+z)/2;
t=sqrt(p*(p-x)*(p-y)*(p-z));
return t;
}


TandyT 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 tandyt 的回复:]
cin>>a>>b>>c>>endl;

修改为 :

cin>>a;
cin>>b;
cin>>c;
cout<<endl;
[/Quote]

还有:

t=sqrt(p*(p-x)(p-y)(p-z));

改为:
t=sqrt(p*(p-x)*(p-y)*(p-z));
ywwj5858792qd 2011-03-07
  • 打赏
  • 举报
回复
1.using namespace std;
2.main 函数返回类型为void
pal513 2011-03-07
  • 打赏
  • 举报
回复
是不是少了 ( use namespace std; )?
TandyT 2011-03-07
  • 打赏
  • 举报
回复
cin>>a>>b>>c>>endl;

修改为 :

cin>>a;
cin>>b;
cin>>c;
cout<<endl;
斯巴达克斯 2011-03-07
  • 打赏
  • 举报
回复
“”里的东西是string型变量,不能直接用>>输入的,你得重载>>运算符才行
TandyT 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 lanbingerfly 的回复:]
引用 6 楼 tandyt 的回复:
完整的为:


C/C++ code

#include<iostream.h>
#include<conio.h>
#include<math.h>
float area(float x,float y,float z);
int main()
{ float a,b,c,s;
cout<<"please input 3 sides ……
[/Quote]

我这里编译没错的,是不是你复制时,复制了一些VC编译器不能识别的东西?你先存储到 记事本,然后再拷贝到 VC 里面编译试试
lanbingerfly 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 tandyt 的回复:]
完整的为:


C/C++ code

#include<iostream.h>
#include<conio.h>
#include<math.h>
float area(float x,float y,float z);
int main()
{ float a,b,c,s;
cout<<"please input 3 sides of one triangle:"<<……
[/Quote]编译时有更多的错误:Compiling...
liu.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(11) : error C2018: unknown character '0xa3'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(11) : error C2018: unknown character '0xbb'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(12) : error C2146: syntax error : missing ';' before identifier 'cin'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(12) : error C2018: unknown character '0xa3'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(12) : error C2018: unknown character '0xbb'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(13) : error C2146: syntax error : missing ';' before identifier 'cin'
C:\Program Files\Microsoft Visual Studio\MyProjects\liu\liu.cpp(28) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
执行 cl.exe 时出错.

liu.obj - 1 error(s), 0 warning(s)
怎么回事?
lanbingerfly 2011-03-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 tandyt 的回复:]
cin>>a>>b>>c>>endl;

修改为 :

cin>>a;
cin>>b;
cin>>c;
cout<<endl;
[/Quote]
我看很多代码中都这么连着写的。这样写不行吗?
Eleven 2011-03-07
  • 打赏
  • 举报
回复

#include "stdafx.h"

#include<iostream>

#include<conio.h>
#include<math.h>
using namespace std;
float area(float x,float y,float z);

int main()
{
float a,b,c,s;
cout<<"please input 3 sides of one triangle:"<<endl;
cin>>a;
cin>>b;
cin>>c;
if(a <=0 || b <=0 || c<=0)
{
cout<<"input error"<<endl;
return -1;
}
cout<<a<<","<<b<<","<<c<<endl;
s=area(a,b,c);
cout<<"area of triangle is:"<<s<<endl;
return 0;
}
float area(float x,float y,float z)
{
float p,t;
p=(x+y+z)/2;
t=sqrt(p*(p-x)*(p-y)*(p-z));
return t;
}

需要检查与一下,a,b,c是否为负数

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧