大家帮我检查一下错误

来源:百度知道 编辑:UC知道 时间:2024/06/10 01:13:05
大家帮我检查一下,系统报了1个错误:
#include<iostream.h>
void main()
{
float S=0;
const float PI=3.1415926535897932384626F;
const int h=4;
const float r=2.5F;
S=PI*r*r*h;
cout<<"圆柱体的体积为:"<<setprecision(3)<<S<<endl;
return 0;
}
#include<iostream.h>
#include<iomanip.h>
void main()
{
float V=0;//初始化体积V的值为0
const float PI=3.14159265358979F;//确定圆周率为常量
const float H=4;//确定圆柱的高H为常量
const float R=2.5F;//确定圆柱底面圆半径R为常量
V=PI*R*R*H;//确定公式
cout<<"圆柱体的体积为:"<<setprecision(3)<<V<<endl;//输出结果
}

系统报错:
Compiling...
实验.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/求圆柱体体积.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

求圆柱体体积.exe - 1 error(s),

改成下面的就行了,在dev运行通过了。
#include<iostream.h>
#include<iomanip.h>
using namespace std;
int main()
{
float V=0;//初始化体积V的值为0
const float PI=3.14159265358979F;//确定圆周率为常量
const float H=4;//确定圆柱的高H为常量
const float R=2.5F;//确定圆柱底面圆半径R为常量
V=PI*R*R*H;//确定公式
cout<<"圆柱体的体积为:"<<setprecision(3)<<V<<endl;//输出结果
system("pause");
return 0;
}

void main()
就不要return

#include<iostream.h>
#include<iomanip.h>
void main()
{
float V=0;//初始化体积V的值为0
const float PI=3.14159265358979F;//确定圆周率为常量
const float H=4;//确定圆柱的高H为常量
const float R=2.5F;//确定圆柱底面圆半径R为常量
V=PI*R*R*H;//确定公式
cout<<"圆柱体的体积为:"<<setprecision(3)<<V<<endl;//输出结果
}

void 和 return是不能出现在同一个函数中的,void是表示函数没返回值。