注册 登录
编程论坛 C++教室

刚开始接触c++希望大家帮忙看下哪里不对

wuguangqin 发布于 2017-03-01 22:49, 1613 次点击
#define PI 3.14
#include<iostream.h>
#include<iomanip.h>
 void main()
{ float r,h,zc,mj,bmj,tj;
 cin>>r>>h;
 zc=2*r*PI;
 mj=r*r*PI;
 bmj=4*PI*r*r*r;
 tj=PI*r*r*r*h;
 cout<<setiosflags(ios::fixed)<<setprecision(2);
 cout<<圆周长<<zc<<endl;
 cout<<圆面积<<mj<<endl;
 cout<<圆球表面积<<bmj<<endl;
 cout<<圆柱体积<<tj<<endl;                 这一行显示有错误 C:\Users\DELL\Desktop\作业1.cpp(15) : error C2059: syntax error : '<<'
}
3 回复
#2
rjsp2017-03-02 08:32
程序代码:
#include <iostream>
#include <iomanip>
using namespace std;

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

int main( void )
{
    double r, h;
    if( !(cin>>r>>h) )
        return 1;

    double circumference   = 2*M_PI*r;
    double area_round      = M_PI*r*r;
    double area_ball       = 4*M_PI*r*r;
    double volume_cylinder = M_PI*r*r*h;

    cout << setiosflags(ios::fixed) << setprecision(2)
         << "圆周长     = " << circumference   << '\n'
         << "圆面积     = " << area_round      << '\n'
         << "圆球表面积 = " << area_ball       << '\n'
         << "圆柱体积   = " << volume_cylinder << endl;

    return 0;
}
#3
yslief2017-03-03 00:59
cout<<圆周长<<zc<<endl;        中文字没打上双引号
 cout<<圆面积<<mj<<endl;
 cout<<圆球表面积<<bmj<<endl;
 cout<<圆柱体积<<tj<<endl;   
#4
阿呆ddf2017-03-04 19:27
头文件包含格式,应该为 #include <iostream> 或者为 #include "iostream.h"
输出中文字符时要加上双引号,cout<<"圆周长"<<zc<<endl;
最好加上using namespace std;不然编译时可能会产生找不到cin,cout,endl等这样的错误

[此贴子已经被作者于2017-3-4 20:14编辑过]

1