我正在为课堂编写一个代码而且我认为我一直在努力。但是,当我在XCode上编译时,无法从输入中获得任何反馈。
我的代码如下:
/*
James George Hayek
PCCC Assignment 2
Prof Siegel
This program will calculate the area and circumference of a circle.
*/
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
float radius;
float circumference;
float area;
cout << "Please enter the radius of a circle: ";
cin >> radius;
cout << "\n";
circumference = 2 * 3.1416 * radius;
area = 3.1416 * radius * radius;
cout << "************************************" << "\n"
<< "*Area and Circumference of A Circle*" << "\n"
<< "************************************" << "\n"
<< "\tRadius= " << radius << "\n"
<< "\tArea= " << area << "\n"
<< "\tCircumference= " << circumference << "\n";
cin.get();
return 0;
} //end main
好吧,我只是麻烦拍了这个看起来好像这在终端有效,但我无法让它在XCode的控制台中响应。我不应该担心这个吗?
答案 0 :(得分:1)
您在输出中找到了标签:/t
应为\t
。我没有看到代码有任何其他问题。 (测试)
cout << "************************************" << "\n"
<< "*Area and Circumference of A Circle*" << "\n"
<< "************************************" << "\n"
<< "\tRadius=" << radius << "\n"
<< "\tArea=" << area << "\n"
<< "\tCircumference=" << circumference << "\n";
答案 1 :(得分:0)
答案 2 :(得分:0)
'\ t'不是'/ t'。
它应该是:
<< "\tRadius=" << radius << "\n"
<< "\tArea=" << area << "\n"
<< "\tCircumference=" << circumference << "\n";
答案 3 :(得分:0)
其他帖子指出了原因/解决方法。
刚刚注意到:
你的代码在语句中默默地失去了精度,因为隐藏的双重浮动标准转换适用于你的背后:
circumference = 2 * 3.1416 * radius; (since 3.1416 is of type double,
the type of rhs is double).
area = 3.1416 * radius * radius; (same here)
所以,你失去了精力。除非是故意的,否则不要这样做。编译最严格的警告级别虽然不能保证能够解决所有潜伏的问题。
$ 5/10 - “否则,如果是任一操作数 是两倍,另一个是 转换为双倍。“
答案 4 :(得分:0)
圆的面积=(半径*半径)* PI
function area_of_circle($ radius){
$ area = pow($ radius,2)* pi();
返回$ area; }
//给定值$ radius = 2;
$ area = area_of_circle($ radius);
echo“Circle of Radius of Circle:”。$ radius。“ “; echo”Circle of Circle:“。$ area;
答案 5 :(得分:0)
#include<stdio.h>
#include<conio.h>
void main()
{
float radius,area;
clrscr(); // Clear Screen
printf("nEnter the radius of Circle : ");
scanf("%d",&radius);
area = 3.14 * radius * radius;
printf("nArea of Circle : %f",area);
getch();
}