计算圆形区域的问题 [英] calculating the area of a circle problems

查看:62
本文介绍了计算圆形区域的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Complier:Visual C ++ 2005 Express Edition


我编写的程序将编译并执行,但输出总是

相同,不管是什么输入数字为

圆的半径。有人请帮忙!我对此非常陌生,因为你可以告诉我们b $ b。我在下面的代码中遗漏了什么?


#include" stdafx.h"

#include< iostream>

#include< cmath>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main(){

const float Pi = 3.14159;

radius = 0;


cout<< 输入圆的半径:;

cin> radius;


int area = Pi(半径*半径);

cout<< endl

<< 圆的面积= =

<<半径

<< endl;

返回0;

}

Complier: Visual C++ 2005 Express Edition

The program I wrote will compile and execute, but the output is always
the same, no matter what number is entered in for the radius of the
circle. Someone please help! I am extremely new at this, as you can
probably tell. What am I missing with the code below?

#include "stdafx.h"
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;

int main() {
const float Pi = 3.14159;
radius = 0;

cout << "Enter the radius of a circle: ";
cin >radius;

int area = Pi (radius * radius);
cout << endl
<< "Area of the circle is = "
<< radius
<< endl;
return 0;
}

推荐答案

jdcrief写道:
jdcrief wrote:

编译器:Visual C ++ 2005 Express Edition


我编写的程序将编译并执行,但输出总是
Complier: Visual C++ 2005 Express Edition

The program I wrote will compile and execute, but the output is always



它会吗?

It will?


相同,无论输入的半径是多少

圈。有人请帮忙!我对此非常陌生,因为你可以告诉我们b $ b。我在下面的代码中遗漏了什么?


#include" stdafx.h"
the same, no matter what number is entered in for the radius of the
circle. Someone please help! I am extremely new at this, as you can
probably tell. What am I missing with the code below?

#include "stdafx.h"



这段废话是不必要的。它只是处理AFX项目中预编译头文件的定制的一部分。 AFX代表

应用程序框架。 MFC的前任命名者,或微软

基础课程。没有理由将AFX-anything出现在没有使用MFC的
C ++代码中。

This piece of nonsense is unnecessary. It''s simply part of a custom for
handling precompiled headers in AFX projects. AFX stands for
"application frameworks". the former namer of MFC, or Microsoft
Foundation Classes. There is no reason for AFX-anything to appear in
C++ code that doesn''t use MFC.


#include< iostream> ;

#include< cmath>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main(){

const float Pi = 3.14159;

radius = 0;
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;

int main() {
const float Pi = 3.14159;
radius = 0;



这个编译???


这里你指定的是半径,你没有在任何地方定义。

你的程序格式不正确。


它需要一条诊断信息。

This compiles???

Here you are assigning to radius, which you have not defined anywhere.
Your program is ill-formed.

It requires a diagnostic message.


cout<< ; 输入圆的半径:;

cin> radius;


int area = Pi(radius * radius);
cout << "Enter the radius of a circle: ";
cin >radius;

int area = Pi (radius * radius);



这里你关心试图将Pi作为函数调用,但是你将它声明为

浮点数。需要诊断。


我不认为你使用的编译器会编译这个

程序。


我怀疑你继续运行一些以前版本的程序

做了编译,没有注意到新版本的源代码

代码不是编译。


再次尝试编译并注意消息。

Here you care trying to call Pi as a function, but you declared it as a
float. A diagnostic is required.

I don''t think that the compiler you are using will compile this
program.

I suspect that you keep running some previous version of the program
that did compile, without noticing that the new version of the source
code isn''t compiling.

Try compiling it again and pay attention to the messages.


cout<< endl

<< 圆的面积= =

<<半径

<< ENDL;
cout << endl
<< "Area of the circle is = "
<< radius
<< endl;



圆的面积是半径?您没有打印正确的

变量。

The area of the circle is its radius? You are not printing the correct
variable.


" jdcrief"写道:
"jdcrief" writes:

编译器:Visual C ++ 2005 Express Edition


我写的程序将编译并执行,但输出是总是

相同,无论输入什么数字为

圈的半径。有人请帮忙!我对此非常陌生,因为你可以告诉我们b $ b。我在下面的代码中遗漏了什么?


#include" stdafx.h"

#include< iostream>

#include< cmath>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main(){

const float Pi = 3.14159;

radius = 0;


cout<< 输入圆的半径:;

cin> radius;


int area = Pi(radius * radius);
Complier: Visual C++ 2005 Express Edition

The program I wrote will compile and execute, but the output is always
the same, no matter what number is entered in for the radius of the
circle. Someone please help! I am extremely new at this, as you can
probably tell. What am I missing with the code below?

#include "stdafx.h"
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;

int main() {
const float Pi = 3.14159;
radius = 0;

cout << "Enter the radius of a circle: ";
cin >radius;

int area = Pi (radius * radius);



这是一个隐含的乘法,计算机并不直观;制作

显式。


int area = Pi *(半径*半径);


没有需要parens,但如果你想要它们使用

它们没有问题。

That''s an implicit multiply, computers aren''t that intuitive; make it
explicit.

int area = Pi*(radius*radius);

There is no need for parens, but if you want them there is no problem using
them.


cout<< endl

<< 圆的面积= =

<<半径

<< endl;

返回0;

}
cout << endl
<< "Area of the circle is = "
<< radius
<< endl;
return 0;
}



jdcrief张贴:
jdcrief posted:

我在下面的代码中遗漏了什么?


#include" stdafx.h"

#include< iostream>

#include< cmath>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main(){

const float Pi = 3.14159;

radius = 0;
What am I missing with the code below?

#include "stdafx.h"
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;

int main() {
const float Pi = 3.14159;
radius = 0;



称为半径的对象从未定义。


The object known as "radius" was never defined.


cout<< 输入圆的半径:;

cin> radius;


int area = Pi(radius * radius);
cout << "Enter the radius of a circle: ";
cin >radius;

int area = Pi (radius * radius);



这些括号可能意味着正常数学中的乘法,但不是C ++中的
。此外,你使用有符号整数类型(我认为你的

区域永远不应该是负数)。


unsigned area = pi *半径*半径;


-


Frederick Gotham


Those parentheses might mean multiplication in normal mathematics, but not
in C++. Furthermore, you''re using a signed integer type (and I presume your
"area" should never be negative).

unsigned area = pi*radius*radius;

--

Frederick Gotham


这篇关于计算圆形区域的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆